Forums Register Login

how to transfer contol to another gui

+Pie Number of slices to send: Send
am developing a gui based application.my problem is that i want to see a second gui form i created when i click on the continue button on my first form....here is a portion of my code......please i need your help,what should i do in my logic? THANKS
//FORM1 CODE

private class ButtonHandler implements ActionListener,Serializable {



public void actionPerformed(ActionEvent e) {

Form1 form1 = new Form1();


String x = "";
File file = new File("client.txt");

/**
try {
RandomAccessFile Rfile = new RandomAccessFile("client.txt","rw");
long n = 10;
Rfile.seek(n);
} catch(FileNotFoundException j){}catch(IOException nb){}
*/

try {
FormLogic logic = new FormLogic();


PrintWriter out = new PrintWriter(new FileWriter(file));
logic.setName(nameText.getText());
String schooldata = (String) boxForSchoolsComboBox.getSelectedItem();
String graduatedata = (String)graduateDegreeProgramComboBox.getSelectedItem();
String statedata = (String) stateComboBox.getSelectedItem();
String addressdata = addressText.getText();
String citydata = cityText.getText();
String statdata = statetext.getText();
String zipcodedata = zipcodeText.getText();
String countrycode = countryText.getText();
String countrycodedata = countrycodeText.getText();
String areacodedata = areacodeText.getText();
String phonenodata = phonenumberText.getText();
String emaildata = emailaddressText.getText();
String datebatedata = dateofbirthText.getText();
String citizendata =(String) citizenstatusComboBox.getSelectedItem();
boolean radiodata = maleButton.isSelected();


out.println(schooldata);
out.println(graduatedata);
out.println(logic.getName());



out.println(addressdata);
out.println(citydata);
out.println(statdata);
out.println(zipcodedata);
out.println(countrycode);
out.println(countrycodedata);
out.println(areacodedata);
out.println(phonenodata);
out.println(emaildata);
out.println(datebatedata);
if(radiodata == true) {
out.println("MALE");
}
else {out.println("FEMALE");}


out.close();
/**
RandomAccessFile Rfile = new RandomAccessFile("client.txt","rws");

long n =30;
n++;

Rfile.seek(file.length());
Rfile.seek(n);
Rfile.writeBytes(addressdata);

long m =20;
m++;
Rfile.seek(file.lastModified());
Rfile.seek(file.length());
Rfile.writeBytes(citydata);
Rfile.seek(file.length());


Rfile.close();
*/
}catch (IOException e1){
System.out.print("error opening file");
}

//this.launch();

}




//FORM2 CODE....


public class Form1 extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent ae){}

/** Creates a new instance of Form1 */
private JLabel qualificationFormLabel,schoolLabel;
private JLabel graduationdegreeLabel,universityLabel;
private JComboBox graduateDegreeProgramComboBox,boxForSchoolsComboBox;
private JLabel gradeLabel,grescoreLabel;
private JTextField gradeText,universityText;
private JLabel testdateLabel,scoreLabel,toeflscoreLabel,detailsLabel;
private JTextField testdateText,scoreText;
private JButton submitButton;


private JPanel qualificationFormPanel;
private JPanel graduateDegreeProgramPanel,schoolPanel;
private JPanel gradePanel;
private JPanel graduategradePanel;
private JPanel grePanel,testPanel,toeflPanel,detailsPanel,submitPanel;


private JPanel generalPanel;

private Font font, fontGDP;

private String graduateDegreePrograms[] = {"Aeronautics-Astonautics", "Earth Science","Applied Physics ", "Biochemistry", "Education", "Biosciences", "Humanities and Sciences", "Engineering and Applied Sciences", "Architecture", "Law", "Nursing", "Journalism"};
private String school[] = {"Engineering", "Medicine","Law", "Social Sciences", "Humanities", "Education","Sciences"};
public Form1() {
//Set the title of the frame.
super.setTitle("QUALIFICATION DETAILS.....");

font = new Font("Roman", Font.BOLD, 15);
fontGDP = new Font("Tahoma", Font.PLAIN,12);

//Initializing the qualificationFormLabel
qualificationFormLabel = new JLabel("QUALIFICATION DETAILS");
qualificationFormLabel.setFont(font);
qualificationFormLabel.setForeground(Color.black);
qualificationFormLabel.setVisible(true);

//Initializing the qualificationFormPanel
qualificationFormPanel = new JPanel();
qualificationFormPanel.add(qualificationFormLabel);
qualificationFormPanel.setVisible(true);

//Initializing the graduationdegreeLabel
graduationdegreeLabel = new JLabel("GRADUATION DEGREE" +
" PROGRAM:");
graduationdegreeLabel.setFont(fontGDP);
graduationdegreeLabel.setForeground(Color.black);
graduationdegreeLabel.setVisible(true);

//Initializing the graduateDegreeProgramComboBox
graduateDegreeProgramComboBox = new JComboBox();
for(int count1 = 0; count1 <= 11; count1++)
{
graduateDegreeProgramComboBox.addItem(graduateDegreePrograms[count1]);
}
graduateDegreeProgramComboBox.setMaximumRowCount(4);
graduateDegreeProgramComboBox.isEditable();
graduateDegreeProgramComboBox.setVisible(true);
graduateDegreeProgramComboBox.setVisible(true);


//Initializing the gradeLabel
gradeLabel = new JLabel(" GRADE:");
gradeLabel.setFont(fontGDP);
gradeLabel.setForeground(Color.black);
gradeLabel.setVisible(true);


//Initializing the gradeText
gradeText = new JTextField(8);
gradeText.setFont(fontGDP);
gradeText.setForeground(Color.BLACK);
gradeText.setVisible(true);

//Initializing the gradePanel
gradePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
gradePanel.add(gradeLabel);
gradePanel.add(gradeText);


//Initializing the graduateDegreeProgramPanel
graduateDegreeProgramPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
graduateDegreeProgramPanel.add(graduationdegreeLabel);
graduateDegreeProgramPanel.add(graduateDegreeProgramComboBox);
graduateDegreeProgramPanel.add(gradePanel);
graduateDegreeProgramPanel.setVisible(true);

// Initializing boxForSchoolsComboBox
boxForSchoolsComboBox = new JComboBox();
for(int count = 0; count <= 6; count++)
{
boxForSchoolsComboBox.addItem(school[count]);
}
boxForSchoolsComboBox.setMaximumRowCount(3);
boxForSchoolsComboBox.isEditable();
boxForSchoolsComboBox.setVisible(true);

// Initializing schoolLabel
schoolLabel = new JLabel("School:");
schoolLabel.setFont(fontGDP);
schoolLabel.setForeground(Color.BLACK);
schoolLabel.setVisible(true);

//Initializing the universityLabel
universityLabel = new JLabel(" UNIVERSITY:");
universityLabel.setFont(fontGDP);
universityLabel.setForeground(Color.BLACK);
universityLabel.setVisible(true);

//Initiallizing the universityText
universityText = new JTextField(15);
universityText.setFont(fontGDP);
universityText.setForeground(Color.BLACK);
universityText.setVisible(true);



// Initializing the schoolPanel
schoolPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
schoolPanel.add( schoolLabel);
schoolPanel.add(boxForSchoolsComboBox);
schoolPanel.add(universityLabel);
schoolPanel.add(universityText);

// Initializing grescoreLabel
grescoreLabel = new JLabel("GRADUATE RECORD EXAMINATION(GRE)SCORES:");
grescoreLabel.setFont(font);
grescoreLabel.setForeground(Color.BLACK);
grescoreLabel.setVisible(true);

// Initializing the grePanel
grePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
grePanel.add(grescoreLabel);

// Initializing testdateLabel
testdateLabel = new JLabel("TESTDATE:");
testdateLabel.setFont(fontGDP);
testdateLabel.setForeground(Color.BLACK);
testdateLabel.setVisible(true);

//Initiallizing the testdateText
testdateText = new JTextField(15);
testdateText.setFont(fontGDP);
testdateText.setForeground(Color.BLACK);
testdateText.setVisible(true);

// Initializing scoreLabel
scoreLabel = new JLabel(" SCORE(%):");
scoreLabel.setFont(fontGDP);
scoreLabel.setForeground(Color.BLACK);
scoreLabel.setVisible(true);

//Initiallizing the scoreText
scoreText = new JTextField(15);
scoreText.setFont(fontGDP);
scoreText.setForeground(Color.BLACK);
scoreText.setVisible(true);

// Initializing the testPanel
testPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
testPanel.add(testdateLabel);
testPanel.add(testdateText);
testPanel.add(scoreLabel);
testPanel.add(scoreText);

// Initializing toeflscoreLabel
toeflscoreLabel = new JLabel("TOEFL SCORE (IF REQUIRED):");
toeflscoreLabel.setFont(fontGDP);
toeflscoreLabel.setForeground(Color.BLACK);
toeflscoreLabel.setVisible(true);

//Initiallizing the scoreText
scoreText = new JTextField(35);
scoreText.setFont(fontGDP);
scoreText.setForeground(Color.BLACK);
scoreText.setVisible(true);


// Initializing the toeflPanel
toeflPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
toeflPanel.add(toeflscoreLabel);
toeflPanel.add(scoreText);


// Initializing detailsLabel
detailsLabel = new JLabel("DETAILS OF RECENT HONORS AND AWARDS:");
detailsLabel.setFont(fontGDP);
detailsLabel.setForeground(Color.BLACK);
detailsLabel.setVisible(true);

//Initiallizing the scoreText
scoreText = new JTextField(50);
scoreText.setFont(fontGDP);
scoreText.setForeground(Color.BLACK);
scoreText.setVisible(true);

// Initializing the detailsPanel
detailsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
detailsPanel.add(detailsLabel);
detailsPanel.add(scoreText);

//Initializing the submitButton
submitButton = new JButton("SUBMIT:");
submitButton.setVisible(true);

//Initializing the buttonHandler
ButtonHandler2 button = new ButtonHandler2();
submitButton.addActionListener(button);

//Initializing the submitPanel
submitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
submitPanel.add(submitButton);


generalPanel = new JPanel(new GridLayout(8,7,0,0));
generalPanel.add(qualificationFormPanel);
generalPanel.add(graduateDegreeProgramPanel);
generalPanel.add(schoolPanel);
generalPanel.add(grePanel);
generalPanel.add(testPanel);
generalPanel.add(toeflPanel);
generalPanel.add(detailsPanel);
generalPanel.add(submitPanel);
generalPanel.setVisible(true);

add(generalPanel);

}


class ButtonHandler2 implements ActionListener,Serializable {
public void actionPerformed(ActionEvent e) {
File file = new File("client2.txt");
try {
PrintWriter out = new PrintWriter(new FileWriter(file));
String graduatedata = (String)graduateDegreeProgramComboBox.getSelectedItem();
String gradedata = gradeText.getText();
String universitydata = universityText.getText();
String boxForSchoolsdata = (String) boxForSchoolsComboBox.getSelectedItem();
String testdatedata = testdateText.getText();
String scoredata = scoreText.getText();



out.println(graduatedata);
out.println(gradedata);
out.println(universitydata);
out.println(boxForSchoolsdata);
out.println(testdatedata);
out.println(scoredata);

out.close();
}catch (IOException i) {
System.out.println("AN ERROR HAS OCCURRED!!!");
}
}



+Pie Number of slices to send: Send
Welcome to the Ranch
You have already been told your code is far too much for anybody to read.
Your indentation is incorrect, as are the forms of your identifiers (no capital letters).
Never write == true.
How do you think you would create a second GUI? A new frame, or a new window or a new dialog?
+Pie Number of slices to send: Send
Indeed, I didn't even bother reading that "code". In quotes, since you didn't UseCodeTags. It's impossible to read that without them.
+Pie Number of slices to send: Send
"am developing a GUI based application.my problem is that i want to see a second gui form i created when i click on the continue button on my first form....here is a portion of my code......please i need your help,what should i do in my logic? THANKS "


Jr Chukwudi you are welcome to Java and JavaRanch.
I believe you are a fellow Nija...

Actually, your code is too lengthy to read but if I got your question right. I think that what you mean is a situation where you have two or more GUIs say ApplicationForm_1.java, ApplicationForm_2.java and ConfirmationPage.java.
You may want a situation where by the user will start with ApplicationForm_1.java and after successful completion he/she will proceed with ApplicationForm_2.java and ConfirmationPage.java on successful completion of ApplicationForm_2.java.

If that is case study above relates to what you are looking for. Then:

Lets assume that each of the Forms contains a launch() which can be called to launch the GUI and an Event Handler for your Continue Button actionPerformed(ActionEvent eve)
e.g.

If your design is such that a particular listener is registered to a component that has its handler method designed in the style shown above.
Then you will be sure that that a click to that Component (say Button) will make the frame containing it to be invisible while making the next frame to be visible.

I will like your feedback on how helpful it is to you
+Pie Number of slices to send: Send
Not much point in trying to read the code, seeing as how Igbe Jr. Chukwudi never did return to the three earlier threads it started.
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1283 times.
Similar Threads
writing to text files
Need to convert Console App to GUI...
how to write to text files without overwriting the original contents
JFrame/JPanel problem
using the seek() method to prevent data overwriting in a text file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:47:12.