Hi! I am just a newbie here! I just wanna ask how to do the file handling in java applet? Do I have to do the certain policy/permission to perform it? If so, how would I do it?
And another one, how can I close the APPLET WINDOW once I click on the exit button. I was able to close the Frame but I can't close the APPLET WINDOW.
can you help me guys?
codes for my program. this is what i have actually. i just started doing this one hmm, 4hrs ago? i've just started with the components that i am going to use:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class CaseStudy extends Applet implements ActionListener, ItemListener
{ Label jlbl1 = new Label("Username:");
Label jlbl2 = new Label("Password:");
Label lbl1 = new Label("Shoe Inventory!");
Label lbl2 = new Label("What would you like to do?");
Label lbl3 = new Label("Type-in the stock number:");
Label lbl4 = new Label("How many pairs?");
Label lbl5 = new Label("Enter the price:");
Label lbl6 = new Label("Others pls. specify:");//size
TextField txt1 = new TextField("",20);
TextField txt2 = new TextField("",20);
TextField txt3 = new TextField("",25); //stock number
TextField txt4 = new TextField("",20); //no. of pairs
TextField txt5 = new TextField("",20); //price
TextField txt6 = new TextField("",20); //size
JButton jb1 = new JButton("Confirm");
JButton jb2 = new JButton("Clear Fields");
JButton jb3 = new JButton("Create");
JButton jb4 = new JButton("Edit");
JButton jb5 = new JButton("Delete");
JButton jb6 = new JButton("Display");
JButton jb7 = new JButton("Search");
JButton jb8 = new JButton("Exit");
JButton jb9 = new JButton("<<Back"); //buttons for file handling
JButton jb9_1 = new JButton("<<Back"); //frame1 create
JButton jb9_2 = new JButton("<<Back"); //frame2 edit
JButton jb9_3 = new JButton("<<Back"); //frame3
Choice chc = new Choice(); //submit and cancel
CheckboxGroup chkb = new CheckboxGroup(); //brand
Checkbox nike = new Checkbox("Nike", chkb, false);
Checkbox adi = new Checkbox("Adidas", chkb, false);
Checkbox n1 = new Checkbox("And1", chkb, false);
Checkbox ske = new Checkbox("Skechers", chkb, false);
Checkbox chk = new Checkbox("Brand");
CheckboxGroup chkb2 = new CheckboxGroup(); //color
Checkbox blu = new Checkbox("Blue", chkb2, false);
Checkbox yel = new Checkbox("Yellow", chkb2, false);
Checkbox pin = new Checkbox("Pink", chkb2, false);
Checkbox bla = new Checkbox("Black", chkb2, false);
Checkbox chk2 = new Checkbox("Color");
CheckboxGroup chkb3 = new CheckboxGroup(); //style
Checkbox high = new Checkbox("High Cut", chkb3, false);
Checkbox low = new Checkbox("Low Cut", chkb3, false);
Checkbox chk3 = new Checkbox("Style");
CheckboxGroup chkb4 = new CheckboxGroup(); //size
Checkbox s6 = new Checkbox("6", chkb4, false);
Checkbox s7 = new Checkbox("7", chkb4, false);
Checkbox s8 = new Checkbox("8", chkb4, false);
Checkbox s9 = new Checkbox("9", chkb4, false);
Checkbox s10 = new Checkbox("10", chkb4, false);
Checkbox chk4 = new Checkbox("Size");
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();
Panel p5 = new Panel();
Panel p6 = new Panel();
Panel p7 = new Panel();
Panel p8 = new Panel();
Panel p9 = new Panel();
Panel p10 = new Panel();
Panel p11 = new Panel();
Panel p12 = new Panel();
Panel p13 = new Panel();
Panel p14=new Panel();
GridLayout gl = new GridLayout(2,2);
GridLayout gl1 = new GridLayout(2,1);
GridLayout gl2 = new GridLayout(6,1);
GridLayout gl3 = new GridLayout(6,6);
FlowLayout fl = new FlowLayout();
GridLayout cgl=new GridLayout(8,1);
Font f = new Font("Font.Monospaced", Font.BOLD, 15);
Font f2 = new Font("Font.Monospaced", Font.BOLD, 25);
Font f3 = new Font("Font.Monospaced", Font.BOLD, 17);
JFrame fra = new JFrame(); // file handling
JFrame fra1 = new JFrame(); //create
JFrame fra2 = new JFrame(); //edit
JFrame fra3 = new JFrame(); //delete
Image img;
String a = "java4.jpg";
AudioClip audioClip;
public void init()
{ img = getImage(getDocumentBase(), a);
setSize(500, 400);
lbl1.setFont(f2);
lbl1.setForeground(Color.green);
lbl1.setBackground(Color.black);
add(lbl1);
jlbl1.setForeground(Color.green);
jlbl1.setFont(f);
p1.add(jlbl1);
p1.add(txt1);
jlbl2.setFont(f);
jlbl2.setForeground(Color.green);
p1.add(jlbl2);
txt2.setEchoChar('*');
p1.add(txt2);
p1.setBackground(Color.black);
p1.setLayout(gl);
p2.setBackground(Color.black);
jb1.setFont(f);
p2.add(jb1);
jb2.setFont(f);
p2.add(jb2);
p3.add(p1);
p3.add(p2);
p3.setLayout(gl1);
add(p3);
jb1.addActionListener(this);
jb2.addActionListener(this);
fra.setLayout(gl2); //frame 1
fra.setTitle("File Handling");
p4.add(jb3);
p4.add(jb4);
p4.add(jb5);
p4.add(jb6);
p4.add(jb7);
p4.add(jb8);
p4.add(jb9);
add(p4);
p4.setFont(f2);
fra.add(p4);
jb3.addActionListener(this);
jb4.addActionListener(this);
jb5.addActionListener(this);
jb6.addActionListener(this);
jb7.addActionListener(this);
jb8.addActionListener(this);
jb9.addActionListener(this);
fra1.setLayout(gl2); //frame for create
fra1.setTitle("Informations");
fra1.setSize(450,500);
p13.setFont(f);
p13.add(lbl3); // stock number
p13.add(txt3);
chk.setFont(f3);
p12.add(chk);
nike.setEnabled(false); //brand
adi.setEnabled(false);
n1.setEnabled(false);
ske.setEnabled(false);
p12.add(nike);
p12.add(adi);
p12.add(n1);
p12.add(ske);
chk2.setFont(f3);
p11.add(chk2);//color
blu.setEnabled(false);
yel.setEnabled(false);
pin.setEnabled(false);
bla.setEnabled(false);
p11.add(blu);
p11.add(yel);
p11.add(pin);
p11.add(bla);
chk3.setFont(f3);
p10.add(chk3); //style
p10.setLayout(fl);
high.setEnabled(false);
low.setEnabled(false);
p10.add(high);
p10.add(low);
chk4.setFont(f3);
p9.add(chk4); //size
s6.setEnabled(false);
s7.setEnabled(false);
s8.setEnabled(false);
s9.setEnabled(false);
s10.setEnabled(false);
p9.add(s6);
p9.add(s7);
p9.add(s8);
p9.add(s9);
p9.add(s10);
p9.add(lbl6);
p9.add(txt6);
lbl4.setFont(f3);
p8.add(lbl4); //no. of pairs
p8.add(txt4);
lbl5.setFont(f3);
p7.add(lbl5); //price
p7.add(txt5);
p6.add(lbl2);//what would you like to do
chc.add("Submit");
chc.add("Cancel");
add(chc);
add(p6);
p6.add(chc);
p6.add(jb9_1);
chk.addItemListener(this);
chk2.addItemListener(this);
chk3.addItemListener(this);
chk4.addItemListener(this);
jb9_1.addActionListener(this);
fra2.setLayout(gl2); //frame for edit
fra2.setLayout(fl);
fra2.add(jb9_2);
jb9_2.addActionListener(this);
fra3.setLayout(gl3); //frame for delete
fra3.setLayout(fl);
fra3.add(jb9_3);
jb9_3.addActionListener(this);
fra1.setLayout(cgl);
fra1.add(p13);
fra1.add(p12);
fra1.add(p11);
fra1.add(p10);
fra1.add(p9);
fra1.add(p8);
fra1.add(p7);
fra1.add(p6);
audioClip = getAudioClip(getCodeBase(), "button-3.wav");
}//init
public void paint(Graphics g)
{
super.paint(g);
g.drawImage(img,0,0,getWidth(),getHeight(),this);
}//paint
public void actionPerformed(ActionEvent x)
{ Object source = x.getSource();
if(source == jb1)
{ audioClip.play();
if(txt1.getText().equals("q") && txt2.getText().equals("a"))
{JOptionPane.showMessageDialog(null,"Welcome " + txt1.getText() + " to Shoe Inventory Sales", "Shoe Inventory Log-in", JOptionPane.INFORMATION_MESSAGE);
fra.setSize(600, 500);
fra.setVisible(true);
audioClip.play();
txt1.setText("");
txt2.setText("");
}//if confirm correct
else
{ JOptionPane.showMessageDialog(null, "Username and Password not found!", "Shoe Inventory Log-in", JOptionPane.ERROR_MESSAGE);
txt1.setText("");
txt2.setText("");
fra.setVisible(false);
audioClip.play();
}//if confirm both wrong
}//confirm
if(source == jb2)
{ audioClip.play();
txt1.setText("");
txt2.setText("");
}//clr
if(source == jb3)
{ audioClip.play();
fra1.setSize(650, 350);
fra1.setVisible(true);
}//jb3
if(source == jb4)
{ audioClip.play();
fra2.setSize(600, 500);
fra2.setVisible(true);
}//jb4
if(source == jb5)
{ audioClip.play();
fra3.setSize(600, 500);
fra3.setVisible(true);
}//jb5
if(source == jb6)
{
}//jb6
if(source == jb7)
{
}//jb7
if(source == jb8)
{ audioClip.play();
fra.dispose();
stop();
}//jb8
if(source == jb9)
{ audioClip.play();
fra.setVisible(false);
}//jb9
if(source == jb9_1)
{ audioClip.play();
fra1.setVisible(false);
}//jb9_1
if(source == jb9_2)
{ audioClip.play();
fra2.setVisible(false);
}//jb9_2
if(source == jb9_3)
{ audioClip.play();
fra3.setVisible(false);
}//jb9_3
}//action
public void itemStateChanged(ItemEvent e)
{ Object y = e.getItemSelectable();
boolean s;
if(y == chk)
{ audioClip.play();
nike.setEnabled(true);
adi.setEnabled(true);
n1.setEnabled(true);
ske.setEnabled(true);
s = chk.getState();
if(s == false)
{ audioClip.play();
nike.setEnabled(false);
adi.setEnabled(false);
n1.setEnabled(false);
ske.setEnabled(false);
}//getState
}//chk brand
if(y == chk2)
{ audioClip.play();
blu.setEnabled(true);
yel.setEnabled(true);
pin.setEnabled(true);
bla.setEnabled(true);
s = chk2.getState();
if(s == false)
{ audioClip.play();
blu.setEnabled(false);
yel.setEnabled(false);
pin.setEnabled(false);
bla.setEnabled(false);
}//getState chk2
}//chk color
if(y == chk3)
{ audioClip.play();
high.setEnabled(true);
low.setEnabled(true);
s = chk3.getState();
if(s == false)
{ audioClip.play();
high.setEnabled(false);
low.setEnabled(false);
}//getState chk3
}//chk style
if(y == chk4)
{ audioClip.play();
s6.setEnabled(true);
s7.setEnabled(true);
s8.setEnabled(true);
s9.setEnabled(true);
}//chk size
}//item
public void stop()
{ System.out.print("Stoppin..");
}
}//main
thanks in advance! :)