adding a progress bar at start of my program

adding a progress bar at start my program

Page 1 of 1

1 Replies - 2737 Views - Last Post: 12 September 2008 - 10:03 PM Rate Topic: -----

#1 wolfy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-September 08

adding a progress bar at start of my program

Post icon  Posted 12 September 2008 - 09:53 AM

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class registration extends JPanel
{
Timer timer;

private Frame f;
private MenuBar mb;
private Menu m1, m2;
private MenuItem mi1, mi2, mi3, mi4, mi0, mj1, mj2;
private TextField lname, fname, minitial, sNum, address, city, contact, email;	
private Label lbl1, lbl2, lbl3, lbl4, lbl5, lbl6;	
private Button show, save, open, clear, exit;


public void launchFrame()
	{	

	f = new Frame("Student Organization Registration");
	
	mb = new MenuBar();
	m1 = new Menu("File");
	m2 = new Menu("Help");
	
	mi0 = new MenuItem("Show");
	mi1 = new MenuItem("Save");
	mi2 = new MenuItem("Open");
	mi3 = new MenuItem("Clear");
	mi4 = new MenuItem("Exit");
	
	mj1 = new MenuItem("About Author");
	mj2 = new MenuItem("About System");
	
	mb.add(m1);
	mb.setHelpMenu(m2);
	
	m1.add(mi0);
	m1.add(mi1);
	m1.add(mi2);
	m1.add(mi3);
	m1.add(mi4);
	m2.add(mj1);
	m2.add(mj2);

	lbl1 = new Label("Name");
	lbl2 = new Label("Student Number: ");
	lbl3 = new Label("Address:");
	lbl4 = new Label("City: " );
	lbl5 = new Label("Contact Number: ");
	lbl6 = new Label("Email");

	fname = new TextField(15);
	minitial = new TextField(2);
	lname = new TextField(20);
	sNum = new TextField(10);
	address = new TextField(25);
	city = new TextField(8);
	contact = new TextField(9);
	email = new TextField(12);


f.setLayout(new GridLayout(6,1));

	Panel p1 = new Panel();
		p1.add(lbl1);
		p1.add(fname);
		p1.add(minitial);
		p1.add(lname);
	f.add(p1);

	Panel p2 = new Panel();
		p2.add(lbl2);
		p2.add(sNum);
 	CheckboxGroup gender = new CheckboxGroup();
   	p2.add(new Checkbox("Male",gender,false));
   	p2.add(new Checkbox("Female",gender,false));
	f.add(p2);

	Panel p3 = new Panel();
		p3.add(lbl3);
		p3.add(address);
		p3.add(lbl4);
		p3.add(city);
	f.add(p3);	

	Panel p4 = new Panel();
		p4.add(lbl5);
		p4.add(contact);
		p4.add(lbl6);
		p4.add(email);
	f.add(p4);

	Panel p0 = new Panel();
		save = new Button("Save");
		p0.add(save);
		clear = new Button("Clear");
		p0.add(clear);
		exit = new Button("Exit");
		p0.add(exit);
	f.add(p0);

	fname.setText("<First Name Here>");
	lname.setText("<Last Name Here>");

	f.setBackground(Color.gray);
	f.setResizable(false);
	f.setMenuBar(mb);
	f.setSize(500,300);
	f.setVisible(true);
	
// Attatching listeners to menu items and  buttons

		exit.addActionListener(new exitSoftware());
	mi4.addActionListener(new exitSoftware());
	clear.addActionListener(new clearText());	
	 	 mi3.addActionListener(new clearText());

	save.addActionListener(new saveText());
		  mi1.addActionListener(new saveText());

		  open.addActionListener(new openText());
	mi2.addActionListener(new openText());
}	



private class exitSoftware implements ActionListener {
	  public void actionPerformed(ActionEvent e) {

//===============================================

//public Reminder(int seconds) {
//	timer = new Timer();
//	timer.schedule(new RemindTask(), seconds * 1000);
// }

//  class RemindTask extends TimerTask {
//	public void run() 
//		{
//			  timer.cancel(); //Terminate the timer thread
//		System.exit(0);
//			}
//}
//===============================================
	int ok = JOptionPane.showConfirmDialog(null,"are you 	sure","Confirmation",JOptionPane.YES_NO_OPTION);
//new Reminder(5);
	if (ok == JOptionPane.YES_OPTION)
		{ System.exit(0); }
	else
		{ }
	 } 
	  }


private class clearText implements ActionListener {
	  public void actionPerformed(ActionEvent e) {
	cleartxt();
	 }
}

private class saveText implements ActionListener {
	  public void actionPerformed(ActionEvent e) {
	saveFiles();
	 }
}
private class openText implements ActionListener {
	  public void actionPerformed(ActionEvent e) {
	openFiles();
	 }
}

// clearing all textfields
public void cleartxt()
	{
	  fname.setText("");
	minitial.setText("");
	lname.setText("");
	sNum.setText("");
	address.setText("");
	contact.setText("");
	}

public void openFiles()
	{
	  fname.setText("");
	minitial.setText("");
	lname.setText("");
	sNum.setText("");
	address.setText("");
	contact.setText("");
	}
// saving files into texts

public void saveFiles()
{
	try
	{
	File fileNf = new File("FirstName.txt");
	File fileNl = new File("LastName.txt");
	File fileNm = new File("Middle.txt");
	File fileS = new File("Student_Number.txt");
	File fileA = new File("Address.txt");
	File fileC = new File("Contact.txt");
	File fileCy = new File("City.txt");
	
	String Sfname = fname.getText();
	String Sminitial = minitial.getText();
	String Slname = lname.getText();
	String SsNum = sNum.getText();
	String Saddress = address.getText();
	String Scontact = contact.getText();
	String SCity = city.getText();
	
	PrintWriter Nf = new PrintWriter(new FileWriter(fileNf));
	PrintWriter Nl = new PrintWriter(new FileWriter(fileNl));
	PrintWriter Nm = new PrintWriter(new FileWriter(fileNm));
	PrintWriter S = new PrintWriter(new FileWriter(fileS));
	PrintWriter A = new PrintWriter(new FileWriter(fileA));
	PrintWriter C = new PrintWriter(new FileWriter(fileC));
	PrintWriter Cy = new PrintWriter(new FileWriter(fileCy));

	Nf.print(Sfname);
	Nl.print(Slname);
	Nm.print(Sminitial);
	A.print(Saddress);
	C.print(Scontact);
	S.print(SsNum);
	Cy.print(SCity);

	Nf.close();
	Nl.close();
	Nm.close();
	A.close();
	C.close();
	S.close();
	}

	catch(IOException e)
	{
		e.printStackTrace();
	}
}
//====================================================MAIN METHOD
	public static void main(String args[])	
	{

	registration reg = new registration();
	reg.launchFrame();
	}
}
  





this is my working program, i need to add a progress bar before the launchframe is launched.... can anyone pls help, i have alot of tutorials and samples about progress bars but i cant seem to integrate it to my working code... also how to get the string i saved from the text file and put it back to the textfields, this can already save in textfiles but cant retrieve it...

Is This A Good Question/Topic? 0
  • +

Replies To: adding a progress bar at start of my program

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: adding a progress bar at start of my program

Posted 12 September 2008 - 10:03 PM

You are adding and ActionListener


		  open.addActionListener(new openText());


to the JButton open that is not created anywhere to your code will crash on a null pointer exception

As far as the progress bar is concerned your processing will take a few milliseconds so your progress bar will show up for a few millisecond... are you really sure you want to show it ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1