Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Swing Problem

  Asked By: Thelma    Date: Jan 23    Category: Java    Views: 501

I have designed a GUI which is a simple login Screen, the code is as below,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class logInApplet extends JApplet
public void init()
getContentPane().add(new LogIn(),BorderLayout.CENTER);
class LogIn extends JPanel
JSeparator sep = new JSeparator();

JLabel title = new JLabel("LOGIN FORM");
JLabel userid = new JLabel("User ID",JLabel.LEFT);
JLabel pwd = new JLabel("Password", JLabel.LEFT);

JTextField uid = new JTextField(25);
JTextField passwd = new JTextField(25);

JButton signin = new JButton("SignIn");
JButton cancel = new JButton("Cancel");

public LogIn()
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();


title.setFont(new Font("Times-Roman",Font.BOLD,40));
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridwidth = GridBagConstraints.REMAINDER;

gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0,0,10,0);

userid.setFont(new Font("Times-Roman", Font.BOLD,22));
gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = 1;
gbc.insets = new Insets(0,0,0,0);

gbc.gridwidth = GridBagConstraints.REMAINDER;

pwd.setFont(new Font("Times-Roman", Font.BOLD,22));
gbc.gridwidth = 1;

gbc.gridwidth = GridBagConstraints.REMAINDER;

ButtonPanel buttonPanel = new ButtonPanel();

gbc.anchor = GridBagConstraints.SOUTH;
gbc.insets = new Insets(15,0,0,0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 7;


class ButtonPanel extends JPanel
JPanel buttonPanel = new JPanel();
JSeparator seperator = new JSeparator();

public ButtonPanel()
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
setLayout(new BorderLayout(0,5));
public void add(JButton button)

there is a runtime error(IO Exception while reading, using appletviewer) in
this, should i include the <applet> tag to remove the same or there is some
other problem.
I want to make this to run as an application, what changes should I make to do
Also, how do i check on click of SIGNIN that the values entered are there in the
table(how do i get JDBC going here)



2 Answers Found

Answer #1    Answered By: Saxon Anderson     Answered On: Jan 23

About java  IO Exception I'm not sure i don't have java on my
computer now and i don't have time to try it now(Sorry!)

If you want to make applet an aplication you should delete "extends
JApplet" and start as if you write a normal application
"public static void  main(String [] args)"
then you should creat a Frame
"Frame xxx = new Frame("the name you want to appear");"
then you can set the default exit opertion for the frame
you can add any panel to the frame as follow:
" xxx.agetContentPane().add(Panel);"
after you add the Panels you want to the frame you should write

To make sure that the value entered  are there you can make a search
using a loop (What do you mean by JDBC?)

Answer #2    Answered By: Geraldine Perkins     Answered On: Jan 23

Visual Cafe Comes bundled with JDBC and a great
manual, it's off the market but not bad at all.

Didn't find what you were looking for? Find more on Swing Problem Or get search suggestion and latest updates.