I created 2 classes in 1 file. One refers to notepad and second refers to loading screen progressBar
.
But when I tried to execute it the progress bar frame remains on the screen and only close when I hit the close button. I want to close progress bar automatically without hit that close button after its 100% not the other frame.
public class swingNotePad extends MouseAdapter implements ActionListener,MouseListener{
JFrame f;
JTextArea txt;
JMenuBar mb;
JMenu m1,m2,m3,m4,m5;
JMenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7,mi8;
JPopupMenu pm;
JSeparator js,js2;
public void MethodswingNotePad(){
f=new JFrame("Developed by UC");
txt=new JTextArea();
txt.setBounds(0,0,600,570);
js=new JSeparator();
mb=new JMenuBar();
m1=new JMenu("File");
js2=new JSeparator(SwingConstants.VERTICAL);
m2=new JMenu("Edit");
m3=new JMenu("Format");
m4=new JMenu("View");
m5=new JMenu("Help");
mi1=new JMenuItem("Cut");
mi2=new JMenuItem("Copy");
mi3=new JMenuItem("Paste");
mi4=new JMenuItem("Select All");
mi5=new JMenuItem("cut");
mi6=new JMenuItem("copy");
mi7=new JMenuItem("paste");
mi8=new JMenuItem("select all");
m2.add(mi1);
m2.addSeparator();
m2.add(mi2);
m2.addSeparator();
m2.add(mi3);
m2.addSeparator();
m2.add(mi4);
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi4.addActionListener(this);
pm=new JPopupMenu();
pm.add(mi5);pm.add(mi6);pm.add(mi7);pm.add(mi8);
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
mb.add(m5);
f.add(txt);f.add(pm);
f.setJMenuBar(mb);
f.setSize(600,600);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==mi1){
txt.cut();
}
if(e.getSource()==mi2){
txt.copy();
}
if(e.getSource()==mi3){
txt.paste();
}
if(e.getSource()==mi4){
txt.selectAll();
}
}
public static void main(String...args){
swingNotePad a=new swingNotePad();
swingProgressBar2 obj=new swingProgressBar2();
obj.iterate();
a.MethodswingNotePad();
}
}
class swingProgressBar2 extends JFrame{
JProgressBar pb;
JLabel l;
int i=0,n=0;
swingProgressBar2(){
pb=new JProgressBar(0,2000);
pb.setBounds(50,60,150,40);
l=new JLabel("Loading...");
l.setBounds(120,20,100,20);
add(pb);add(l);
pb.setStringPainted(true);
pb.setValue(0);
setSize(300,300);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
if(i==2000){
System.exit(0) ; }
}
public void iterate(){
while(i<2001){
try{
i+=100;
pb.setValue(i);
Thread.sleep(75);
}
catch(Exception e){
System.out.println(e);
}
}
}
}