0

Sorry I've asked a question about my GUI already but it's due Monday and I still having a few problems with it....

1.
When the GUIs opens it opens so that I have to change the size manually to view it i.e. the toolbar appears. Is there a way I can get my program to set the size of my GUI so its a decent size when it opens on screen?

2.
Also does anyone know how to make the text of a text field into text type so it can be tested like this
if(textField1 == "John")

I tried if(textField1.getText( ) == "John") but I get an error alert box

Thanks,
Sean

GUI is as follows:

/* Generated by Together */
import javax.swing.JFrame;
import java.awt.event.WindowEvent;
import java.awt.Label;
import java.awt.Button;
import java.awt.Font;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;


public class TaxiGUI extends JFrame {
/** Creates new form JFrame */
public TaxiGUI() {
initGUI();
pack();
}


public static void main(String arg[]) //added
{
TaxiGUI taxi = new TaxiGUI( ); //new
taxi.setVisible(true);
System.out.println("Hello World!");


}


/** This method is called from within the constructor to initialize the form. */
private void initGUI() {
label1.setText("ONLINE TAXI SERVICE");
label1.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 24));
label1.setBounds(new java.awt.Rectangle(2, 1, 466, 53));
label1.setForeground(new java.awt.Color(0, 0, 255));
panel1.setLayout(null);
panel1.add(label1);
panel1.add(label2);
panel1.add(textField1);
panel1.add(label3);
panel1.add(label4);
panel1.add(textField2);
panel1.add(button1);
label2.setText("User Name : ");
label2.setBounds(new java.awt.Rectangle(34, 127, 121, 22));
label2.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 20));
label2.setForeground(new java.awt.Color(0, 0, 255));
textField1.setText("");
textField1.setBounds(new java.awt.Rectangle(171, 131, 173, 20));
textField1.setFont(new java.awt.Font("Dialog",java.awt.Font.BOLD,12));
label3.setText("SYSTEM LOGIN");
label3.setBounds(new java.awt.Rectangle(135, 72, 160, 35));
label3.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 18));
label3.setForeground(new java.awt.Color(255,0,0));
label4.setText("Password :");
label4.setBounds(new java.awt.Rectangle(35, 174, 124, 27));
label4.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD,20));
label4.setForeground(new java.awt.Color(0,51,255));
addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
textField2.setText("");
textField2.setBounds(new java.awt.Rectangle(170, 180, 176, 22));
textField2.setFont(new java.awt.Font("Dialog",java.awt.Font.BOLD,12));
button1.setLabel("- LOGIN -");
button1.setBounds(new java.awt.Rectangle(169, 232, 122, 33));
button1.setFont(new java.awt.Font("Book Antiqua", java.awt.Font.BOLD, 18));
button1.setForeground(new java.awt.Color(255,0,0));
button1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){button1ActionPerformed(e);}});
}


/** Exit the Application */
private void exitForm(WindowEvent evt) {
System.exit(0);
}
//Check of text when button is pressed
public void button1ActionPerformed(ActionEvent e)
{
while(textField1 == null)
{
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
}


//if(textField1 == "John" && textField2 == "john123")
if(1 == 1)
{
//payGUI = new PaymentGUI(); //if user name and password is valid
selectionGUI = new MainGUI(); //if user name and password is valid
selectionGUI.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
}
}


private Panel panel1 = new Panel();
private Label label1 = new Label();
private Label label2 = new Label();
private TextField textField1 = new TextField();
private Label label3 = new Label();
private Label label4 = new Label();


private TextField textField2 = new TextField();
private Button button1 = new Button();
// private PaymentGUI payGUI;
private MainGUI selectionGUI;
}

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by server_crash
0


1.
When the GUIs opens it opens so that I have to change the size manually to view it i.e. the toolbar appears. Is there a way I can get my program to set the size of my GUI so its a decent size when it opens on screen?

setSize(width,height);

2.
Also does anyone know how to make the text of a text field into text type so it can be tested like this
if(textField1 == "John")

I tried if(textField1.getText( ) == "John") but I get an error alert box

Use:

if (textField1.getText().equals("John"))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.