Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Swing Problem

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

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();

setLayout(gbl);

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

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

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

add(Box.createHorizontalStrut(10));
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(uid,gbc);

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

add(Box.createHorizontalStrut(10));
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(uid,gbc);

ButtonPanel buttonPanel = new ButtonPanel();
buttonPanel.add(signin);
buttonPanel.add(cancel);

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

}

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));
add(seperator,"North");
add(buttonPanel,"Center");
}
public void add(JButton button)
{
buttonPanel.add(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
this.
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)

Share: 

 

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
"xxx.setDefaultExitOperation(JFrame.EXIT_ON_CLOSE);"
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
"xxx.pack();"
"xxx.show();"

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.




Tagged: