The Artima Developer Community
Sponsored Link

Java Answers Forum
Help with GUI

3 replies on 1 page. Most recent reply: Aug 16, 2002 3:23 PM by David Garton

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Iain Ross

Posts: 1
Nickname: iain
Registered: Aug, 2002

Help with GUI Posted: Aug 5, 2002 1:38 PM
Reply to this message Reply
Advertisement
Hi,

I am new to java so please be kind! Anyway I have been asked to produce a simple gui application. The application will use to windows; a logon window and a main action window. When run the application will display the logon window. If the user successfully logs on then the main window will then be shown. Any advice as to what strategy I should use to control these visually components?

regards,
Iain


thomas

Posts: 42
Nickname: turbomanic
Registered: Jul, 2002

Re: Help with GUI Posted: Aug 5, 2002 3:16 PM
Reply to this message Reply
I'm just learning the applet aspects java myself so I can't be to much help but I can tell you what I know. You need to use javax package(swing) to create the frames. You start with an application and use frames to create the visual aspects to the page. You will need two frames to do what you are trying but thats all I know so far . check here for more I'm not sure if it will help http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html

Mircea SIMION

Posts: 1
Nickname: kerber
Registered: Aug, 2002

Re: Help with GUI Posted: Aug 15, 2002 4:26 AM
Reply to this message Reply
hello, iain. send me a spec of ur app at mirceasimion@home.ro

David Garton

Posts: 3
Nickname: davidkiwi
Registered: Aug, 2002

Re: Help with GUI Posted: Aug 16, 2002 3:23 PM
Reply to this message Reply
Here is something I slapped together very quickly, maybe it'll help you get started. As you can see I just used a normal JTextField for the password, but you'll easily be able to replace this with a proper password box. Anyway here it is, good luck.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class guiExample extends JFrame
{
JButton closeBtn, submitBtn, clearBtn;
JTextField unameTxt, passTxt;

public static void main(String[] args)
{
new guiExample().entryGUI();
}

public void entryGUI()
{
Container frmContent = getContentPane();
frmContent.setLayout(new BorderLayout());

//Create the username label and textfield
JPanel userPanel = new JPanel();
JLabel unameLbl = new JLabel("User name");
unameTxt = new JTextField(15);
userPanel.add(unameLbl);
userPanel.add(unameTxt);

//Create the password label and textfield
JPanel passPanel = new JPanel();
JLabel passLbl = new JLabel("Password");
passTxt = new JTextField(15);
passPanel.add(passLbl);
passPanel.add(passTxt);

//Create the buttons
JPanel buttonPanel = new JPanel();
closeBtn = new JButton("Close");
submitBtn = new JButton("Submit");
clearBtn = new JButton("Clear");
closeBtn.addActionListener(new buttonListener());
submitBtn.addActionListener(new buttonListener());
clearBtn.addActionListener(new buttonListener());
buttonPanel.add(closeBtn);
buttonPanel.add(submitBtn);
buttonPanel.add(clearBtn);

frmContent.add(userPanel, BorderLayout.NORTH);
frmContent.add(passPanel);
frmContent.add(buttonPanel, BorderLayout.SOUTH);

setSize(350, 300);
setLocation(50,100);
setVisible(true);
}

public class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if(source == closeBtn)
System.exit(0);

else if(source == submitBtn)
{
//Grab the user's input and compare it to
//something valid
String uname = unameTxt.getText();
String pass = passTxt.getText();

//I guess here you would have to connect to
//a database so the program could
//compare the user's input against all the
//ones contained in the database.
//For now I'll just compare the user's input
//with "scott" and "tiger".
if(uname.equals("scott") & pass.equals("tiger"))
createMain();
}

else if(source == clearBtn)
{
unameTxt.setText("");
passTxt.setText("");
}
}
}

public void createMain()
{
//make the main window
JFrame mainWindow = new JFrame();
mainWindow.setSize(600, 600);
mainWindow.setVisible(true);

//make the entry window invisible, however I guess
//it would be better to close it completely.
setVisible(false);
}
}

Flat View: This topic has 3 replies on 1 page
Topic: IBM Websphere issue Previous Topic   Next Topic Topic: Is it possible?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use