If I wanted to be able to read in files through PiFluke and have the message han
ID: 3818081 • Letter: I
Question
If I wanted to be able to read in files through PiFluke and have the message handler class interpret them and display them how would I do so? Here is My code..
package example;
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class SimpleFileChooser {
private JFileChooser dialog; // The dialog, which is created when needed.
public void setDefaultDirectory() {
if (dialog != null)
dialog.setCurrentDirectory(null);
}
public void setDefaultDirectory(String directoryName) {
if (dialog == null)
dialog = new JFileChooser();
dialog.setCurrentDirectory(new File(directoryName));
}
public void setDefaultDirectory(File directory) {
if (dialog == null)
dialog = new JFileChooser();
dialog.setCurrentDirectory(directory);
}
public File getInputFile() {
return getInputFile(null,null);
}
public File getInputFile(Component parent) {
return getInputFile(parent,null);
}
public File getInputFile(Component parent, String dialogTitle) {
if (dialog == null)
dialog = new JFileChooser();
if (dialogTitle != null)
dialog.setDialogTitle(dialogTitle);
else
dialog.setDialogTitle("Select Input File");
int option = dialog.showOpenDialog(parent);
if (option != JFileChooser.APPROVE_OPTION)
return null; // User canceled or clicked the dialog's close box.
File selectedFile = dialog.getSelectedFile();
return selectedFile;
}
public File getOutputFile() {
return getOutputFile(null,null,null);
}
public File getOutputFile(Component parent) {
return getOutputFile(parent,null,null);
}
public File getOutputFile(Component parent, String dialogTitle) {
return getOutputFile(parent,dialogTitle,null);
}
public File getOutputFile(Component parent,
String dialogTitle, String defaultFile) {
if (dialog == null)
dialog = new JFileChooser();
if (dialogTitle != null)
dialog.setDialogTitle(dialogTitle);
else
dialog.setDialogTitle("Select Output File");
if (defaultFile == null)
dialog.setSelectedFile(null);
else
dialog.setSelectedFile(new File(defaultFile));
while (true) {
int option = dialog.showSaveDialog(parent);
if (option != JFileChooser.APPROVE_OPTION)
return null; // User canceled or clicked the dialog's close box.
File selectedFile = dialog.getSelectedFile();
if ( ! selectedFile.exists() )
return selectedFile;
else { // Ask the user whether to replace the file.
int response = JOptionPane.showConfirmDialog( parent,
"The file "" + selectedFile.getName()
+ "" already exists. Do you want to replace it?",
"Confirm Save",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE );
if (response == JOptionPane.CANCEL_OPTION)
return null; // User does not want to select a file.
if (response == JOptionPane.YES_OPTION)
return selectedFile; // User wants to replace the file
// A "No" response will cause the file dialog to be shown again.
}
}
}
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>
#include<stdio.h>
#include <time.h>
fstream inoutfile;
/Menu Global Item#define pixTOrc(x) (8*(x-1))/change over pixel into line and col format#define INC 5/Increment Distance Between Menu Items#define ROW 15/Row Value for Menu Item#define COL 8/Column Value for Menu Item//To show the Inventory Main menu alternatives
typedef burn option[15];
choice mainMenu[]= {
"New Record",
"Show",
"Look",
"Updation",
"Erasure",
"Investigation",
"Exit"
};
/* - - Inventory Class - - */class Inventory{
roast itemNo[2],itemName[20];
int qty;
twofold price,amt;
open:
roast *getno(){return itemNo;}
roast *getitem(){ return itemName;}
twofold getamt(){return amt;}
void getdata();
void showdata(int,int);
void showspecific();
void alterspecific(char *,char *);
};
void Inventory :: getdata(){
gotoxy(30,12);
cout<<"Enter Item Number : ?";
cin>>itemNo;
gotoxy(30,14);
cout<<"Enter Item Name : ?";
cin>>itemName;
gotoxy(30,16);
cout<<"Enter Quantity : ?";
cin>>qty;
gotoxy(30,18);
cout<<"Enter Price : ?";
cin>>price;
amt = cost * qty;
}
void Inventory :: showdata(int x,int y){
gotoxy(x,y);
cout.setf(ios::left,ios::adjustfield);
cout<<setw(3)<<itemNo;
cout.setf(ios::left,ios::adjustfield);
cout<<setw(13)<<itemName;
cout<<setw(4)<<qty;
cout.setf(ios::right,ios::adjustfield);
cout.setf(ios::showpoint);
cout.setf(ios::fixed,ios::floatfield);
cout<<setprecision(2)<<setw(8)<<price;
cout.setf(ios::right,ios::adjustfield);
cout.setf(ios::showpoint);
cout.setf(ios::fixed,ios::floatfield);
cout<<setprecision(2)<<setw(15)<<amt;
}
void Inventory :: showspecific(){
gotoxy(30,13);
cout<<"- - Search Item Found- - ";
gotoxy(30,15);
cout<<"Item No : ";
cout.setf(ios::left,ios::adjustfield);
cout<<itemNo;
gotoxy(30,17);
cout<<"Item Name : ";
cout.setf(ios::left,ios::adjustfield);
cout<<itemName;
gotoxy(30,19);
cout<<"Quantity : ";
cout<<qty;
cout.setf(ios::right,ios::adjustfield);
cout.setf(ios::showpoint);
cout.setf(ios::fixed,ios::floatfield);
gotoxy(30,21);
cout<<"Price : ";
cout<<setprecision(2)<<price;
gotoxy(30,23);
cout<<"Amount : ";
cout.setf(ios::right,ios::adjustfield);
cout.setf(ios::showpoint);
cout.setf(ios::fixed,ios::floatfield);
cout<<setprecision(2)<<amt;
}
void Inventory :: alterspecific(char itmno[2],char itmname[20]){
strcpy(itemNo,itmno);
strcpy(itemName,itmname);
gotoxy(30,16);
cout<<"Enter Quantity : ?";
cin>>qty;
gotoxy(30,18);
cout<<"Enter Price : ?";
cin>>price;
amt = cost * qty;
}
/* - Inventory Codes End - - *//* - Menu and every other capacity Code - *//Displays Graphic content in postponing fashionvoid displayMe(int x,int y,constchar *ch,int delayTime){
burn d[2];
int len=strlen(ch);
for(int i=0;i<=len;i++)
{
d[0]=ch[i];
d[1]='';
outtextxy(x+pixTOrc((i+1)*2),y,d);
delay(delayTime);
}
}
/Function which demonstrates loading...progress barvoid loading(){
/progressbar logicint i=1,j,cnt,clrflag=0;
setcolor(BLACK);
j=160;
cnt=5;
for(i=j;i<420;i++){
gotoxy(35,25);
cout<<cnt;
rectangle(j,375,i,405);
outtextxy(240,340,"LOADING ");
if(i==(j+10)){
j=j+13;
i=j;
if(clrflag==1){
clrflag=0;
setcolor(BLACK);
}
else{
clrflag=1;
setcolor(DARKGRAY);
}
cnt=cnt+5;
}
}
delay(500);
}
/Function to showcases all the menu incite messages from the pointer exhibit of choice a[]void normalvideo(int x,int y,char *str)
{
x=pixTOrc(x);
y=pixTOrc(y);
outtextxy(x,y,str);
}
/Function to move the cursor on the menu provoke with an invert video colorvoid reversevideo(int x,int y,char *str)
{
x=pixTOrc(x);
y=pixTOrc(y);
setcolor(YELLOW);/Selected Item
sound(400);
delay(100);
nosound();
outtextxy(x,y,str);
setcolor(WHITE);/Unselected Item
sound(500);
delay(100);
nosound();
}
/Keep Track of which bolt key is displayedchar menu()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
setcolor(WHITE);/Initial Menu Item Colorint i,done;
time_t t;
for(i = 1; i < 7; i++)
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
reversevideo(COL,ROW, mainMenu[0]);
i = done = 0;
do
{
/**status Bar **//Message will be shown as status bar rule
setfillstyle(SOLID_FILL,BLUE);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
bar(pixTOrc(2),pixTOrc(52.5),pixTOrc(75),pixTOrc(55));
setcolor(LIGHTCYAN);
switch(i){
case 0 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Add New Item to Inventory");
break;
case 1 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Display All Items accessible in Inventory");
break;
case 2 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Search for a particular Item in Inventory");
break;
case 3 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Modify the quantiy and value data of Item accessible in Inventory");
break;
case 4 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Deletion of thing from Inventory ");
break;
case 5 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Managerial Analysis To tak Decisions...");
break;
case 6 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Close the Program - > BYE C U @ http://dotnetguts.blogspot.com ");
break;
}
/**status Bar ends**//*****Time display****//Displaying Time logicwhile(!kbhit()){
time(&t);
bar(pixTOrc(2),pixTOrc(55.5),pixTOrc(75),pixTOrc(58));
outtextxy(pixTOrc(5),pixTOrc(56),ctime(&t));
outtextxy(pixTOrc(37),pixTOrc(56),"Download More @ : http://dotnetguts.blogspot.com ");
delay(200);
}
/*****Time show Ends****//Restore Orignal Color and Font Setting
setcolor(WHITE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
int key = getch();
switch (key)
{
case 00:
key = getch();
switch (key)
{
case 72:
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
i- - ;
on the off chance that (i == - 1)
i = 6;
reversevideo(COL,(i*INC)+ROW,mainMenu[i]);
break;
case 80:
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
i++;
on the off chance that (i == 7)
i = 0;
reversevideo(COL, (i*INC)+ROW, mainMenu[i]);
break;
}
break;
case 13:
done = 1;
}
}
while (!done);
return(i+49);
}
/Advertise Screen will showed to use purge screen zone//It can be use for some effective...workvoid advertise(){
setcolor(BLUE);
outtextxy(pixTOrc(30),pixTOrc(20),"URL : http://dotnetguts.blogspot.com ");
outtextxy(pixTOrc(30),pixTOrc(26),"find@myblog.com");
setcolor(YELLOW);
}
/* The capacity is utilized to show the principle menu*/void control_menu()
{
singe decision;
do
{
decision = menu();
switch (decision)
{
case'1':/Add New Item
Stock additem;
inoutfile.open("c:\stock.dat",ios::ate | ios::out | ios::binary);
inoutfile.seekg(0,ios::end);
setfillstyle(SOLID_FILL,BLACK);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
setcolor(YELLOW);
outtextxy(pixTOrc(40),pixTOrc(15),"Add New Item");
additem.getdata();
singe ch;
cin.get(ch);
inoutfile.write((char *) &additem, sizeof(additem));
gotoxy(30,22);
cout<<"- > Item Added in Inventory <-";
flush(inoutfile);
inoutfile.close();
getch();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
publicize();
break;
case'2':/Display All Item in stock
Stock showitem;
staticint count=0;
count++;
inoutfile.open("c:\stock.dat",ios::ate| ios::in | ios::binary);
setfillstyle(SOLID_FILL,BLACK);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
setcolor(YELLOW);
outtextxy(pixTOrc(40),pixTOrc(15),"Inventory Stock");
inoutfile.seekg(0,ios::beg);/goto begin of document
gotoxy(28,11);
cout<<" No "<<" Item Name "<<" qty "<<" cost "<<" sum";
gotoxy(28,12);
cout<<"- - - - ";
int x=30,y=13;
while(i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.