Java buttons help???

S

StillillWill

Ok so I've got two JFrames and I'm trying to make the buttons in the
frames open a new class in the same window one class is GUIMain and one
class is GUICustomer... here's the code can anyone help me???

GUIMain:


public class GUIMain extends javax.swing.JFrame
{
public GUIMain()
{
initComponents();
}


private void initComponents()
{
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

getContentPane().setLayout(null);

setTitle("Main Menu");
setName("Main Menu");
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent
evt)
{
exitForm(evt);
}
});

jLabel1.setText("Main Menu:");
getContentPane().add(jLabel1);
jLabel1.setBounds(150, 10, 64, 20);

jButton1.setText("Customer");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});

getContentPane().add(jButton1);
jButton1.setBounds(10, 40, 90, 26);

jButton2.setText("Vehicle");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

getContentPane().add(jButton2);
jButton2.setBounds(110, 40, 76, 26);

jButton3.setText("Rental");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});

getContentPane().add(jButton3);
jButton3.setBounds(200, 40, 70, 26);

jButton4.setText("Close");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});

getContentPane().add(jButton4);
jButton4.setBounds(280, 40, 66, 26);

pack();
java.awt.Dimension screenSize =
java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(365, 120));

setLocation((screenSize.width-365)/2,(screenSize.height-120)/2);
}

private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:close
System.exit(0);
}

private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:rental
}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:vehicle
}

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:customer
Process p = rt.exec("GUICustomer.class") ;
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new GUIMain().show();
}


// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
// End of variables declaration

}


GUICustomer:


public class GUICustomer extends javax.swing.JFrame {

public GUICustomer() {
initComponents();
}


private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jTextField10 = new javax.swing.JTextField();
jTextField11 = new javax.swing.JTextField();
jTextField12 = new javax.swing.JTextField();
jTextField13 = new javax.swing.JTextField();
jTextField14 = new javax.swing.JTextField();
jTextField15 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();

getContentPane().setLayout(null);

setTitle("Customer");
setName("Customer");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

jLabel1.setText("Customer:");
getContentPane().add(jLabel1);
jLabel1.setBounds(100, 10, 59, 20);

jLabel2.setText("Name:");
getContentPane().add(jLabel2);
jLabel2.setBounds(20, 40, 36, 20);

jLabel3.setText("Licence Number:");
getContentPane().add(jLabel3);
jLabel3.setBounds(20, 70, 96, 20);

jLabel4.setText("Date of Birth:");
getContentPane().add(jLabel4);
jLabel4.setBounds(20, 100, 73, 16);

jLabel5.setText("Customer ID:");
getContentPane().add(jLabel5);
jLabel5.setBounds(20, 130, 73, 20);

jLabel6.setText("Address:");
getContentPane().add(jLabel6);
jLabel6.setBounds(20, 160, 51, 20);

jLabel7.setText("Phone Number:");
getContentPane().add(jLabel7);
jLabel7.setBounds(20, 280, 87, 20);

jLabel8.setText("Date:");
getContentPane().add(jLabel8);
jLabel8.setBounds(20, 310, 29, 20);

jTextField1.setText("Forename");
getContentPane().add(jTextField1);
jTextField1.setBounds(130, 40, 61, 20);

jTextField2.setText("Surname");
getContentPane().add(jTextField2);
jTextField2.setBounds(200, 40, 55, 20);

jTextField3.setText("Licence Number");
getContentPane().add(jTextField3);
jTextField3.setBounds(130, 70, 95, 20);

jTextField4.setText("DD");
getContentPane().add(jTextField4);
jTextField4.setBounds(130, 100, 22, 20);

jTextField5.setText("MM");
getContentPane().add(jTextField5);
jTextField5.setBounds(160, 100, 22, 20);

jTextField6.setText("YY");
getContentPane().add(jTextField6);
jTextField6.setBounds(190, 100, 18, 20);

jTextField7.setText("Customer ID");
getContentPane().add(jTextField7);
jTextField7.setBounds(130, 130, 74, 20);

jTextField8.setText("Address Line 1");
getContentPane().add(jTextField8);
jTextField8.setBounds(130, 160, 87, 20);

jTextField9.setText("Address Line 2");
getContentPane().add(jTextField9);
jTextField9.setBounds(130, 190, 87, 20);

jTextField10.setText("Address Line 3");
getContentPane().add(jTextField10);
jTextField10.setBounds(130, 220, 87, 20);

jTextField11.setText("Address Line 4");
getContentPane().add(jTextField11);
jTextField11.setBounds(130, 250, 87, 20);

jTextField12.setText("Telephone Number");
getContentPane().add(jTextField12);
jTextField12.setBounds(130, 280, 111, 20);

jTextField13.setText("DD");
getContentPane().add(jTextField13);
jTextField13.setBounds(130, 310, 22, 20);

jTextField14.setText("MM");
getContentPane().add(jTextField14);
jTextField14.setBounds(160, 310, 22, 20);

jTextField15.setText("YY");
getContentPane().add(jTextField15);
jTextField15.setBounds(190, 310, 18, 20);

jButton1.setText("Add");
getContentPane().add(jButton1);
jButton1.setBounds(20, 350, 56, 26);

jButton2.setText("Remove");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

getContentPane().add(jButton2);
jButton2.setBounds(80, 350, 80, 26);

jButton3.setText("Update");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});

getContentPane().add(jButton3);
jButton3.setBounds(170, 350, 74, 26);

jButton4.setText("Save");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});

getContentPane().add(jButton4);
jButton4.setBounds(30, 380, 62, 26);

jButton5.setText("Main");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton5MouseClicked(evt);
}
});

getContentPane().add(jButton5);
jButton5.setBounds(100, 380, 61, 26);

jButton6.setText("Rental");
jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton6MouseClicked(evt);
}
});

getContentPane().add(jButton6);
jButton6.setBounds(170, 380, 70, 26);

jButton7.setText("Vehicle");
jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton7MouseClicked(evt);
}
});

getContentPane().add(jButton7);
jButton7.setBounds(70, 410, 76, 26);

jButton8.setText("Close");
jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton8MouseClicked(evt);
}
});

getContentPane().add(jButton8);
jButton8.setBounds(150, 410, 66, 26);

pack();
java.awt.Dimension screenSize =
java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(280, 480));

setLocation((screenSize.width-280)/2,(screenSize.height-480)/2);
}

private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {
System.exit(0);
}

private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

private void formMouseClicked(java.awt.event.MouseEvent evt) {
// Add your handling code here:
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new GUICustomer().show();
}


private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField13;
private javax.swing.JTextField jTextField14;
private javax.swing.JTextField jTextField15;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;


}
 
A

Andrew Thompson

Ok so I've got two JFrames and I'm trying to make the buttons in the
frames open a new class in the same window one class is GUIMain and one
class is GUICustomer... here's the code can anyone help me???

That depends.

First comment I'll make is this. It does not require 429
lines of your code for us to tell that you have no clue
what you are doing.

When posting code examples, please trim them down
to an SSCCE. <http://www.physci.org/codes/sscce>

Secondly, your statement of what you are trying to do is
not very clear to me, what do you mean by 'in the same
window'? 'open a new class' - what class?
GUIMain/Customer? Something else again?

Third, you have not asked a specific question.

So.. post an SSCCE (< 100 lines), explain exactly
what you are trying to achieve (with reference to the code),
and ask a specific question, and that help is more
likely to happen.

(Oh, and, same deal with the subject of this one,
such vague titles underline how little you have
actually thought about these problems)

And lastly, please fix that sticky '?' key.

Andrew T.
 
S

StillillWill

Sorry Andrew I'm new at this and thanks for the pointers.

In respect to these lines of code:

private void jButton1MouseClicked(java.awt.event.MouseEvent evt)
{
// Add your handling code here:customer

}

How do I make this MouseClicked action open the GUICustomer.java file?

Sorry if that's not straight forward enough, any help is really greatly
appreciated and thanks in advance.

Will
 
A

Andrew Thompson

Sorry Andrew I'm new at this and thanks for the pointers.

No worries - we were all new once, and if there's one
mistake the 'old dogs' can make is presuming they
do not need to learn *more*. ;-)
How do I make this MouseClicked action open the GUICustomer.java file?

OK - it seems this conversation is effectively split
across two titles. I have decided to concetrate on
the other one* (it has code, and further comments
questions).

*
<http://groups.google.com/groups?selm=1168146386.378312.113990@i15g2000cwa.googlegroups.com>

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top