GUI

GUI

whats wrong with my code?

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

class prog3 extends JFrame
{
JLabel lbl,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lb18,lbl9,lbl10,lbl11,lbl12;
JTextField txt,txt1,txt2,txt3,txt4,txt5,txt6,txt7,txt8,txt9,txt10,txt11;
JTextArea area;
//JComboBox cb;
//JButton btn1,btn2,btn3,btn4,btn5,btn6;
SpringLayout lay;

public prog3()
{
super("Employee Details");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(350,300);
lay=new SpringLayout();
setLayout(lay);
widgets();
}

public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new prog3().setVisible(true);
}
});
}

public void widgets()
{
lbl=new JLabel("Patient ID:");
txt=new JTextField(12);

lbl1=new JLabel("First Name:");
txt1=new JTextField(12);

lbl2=new JLabel("Last Name:");
txt2=new JTextField(12);

lbl3=new JLabel("Gender:");
txt3=new JTextField(12);

lbl4=new JLabel("Date Of Birth:");
txt4=new JTextField(12);

lbl5=new JLabel("Address:");
area=new JTextArea(10,8);

lbl6=new JLabel("Phone Number:");
txt5=new JTextField(12);

lbl7=new JLabel("Patient Occupation:");
txt6=new JTextField(12);

lbl8=new JLabel("Marital Status:");
txt7=new JTextField(12);

lbl9=new JLabel("Account Type:");
txt8=new JTextField(12);

lbl10=new JLabel("Company Name");
txt9=new JTextField(12);

lbl11=new JLabel("Age:");
txt10=new JTextField(12);

lbl12=new JLabel("Weight:");
txt11=new JTextField(12);


getContentPane().add(lbl1);
getContentPane().add(txt1);


getContentPane().add(lbl);
getContentPane().add(txt);

getContentPane().add(lbl2);
getContentPane().add(txt2);

getContentPane().add(lbl3);
getContentPane().add(txt3);

getContentPane().add(lbl4);
getContentPane().add(txt4);

getContentPane().add(lbl5);
getContentPane().add(txt5);

getContentPane().add(lbl6);
getContentPane().add(txt5);

getContentPane().add(lbl7);
getContentPane().add(txt6);

getContentPane().add(lbl8);
getContentPane().add(txt7);

getContentPane().add(lbl9);
getContentPane().add(txt8);

getContentPane().add(lbl10);
getContentPane().add(txt9);

getContentPane().add(lbl11);
getContentPane().add(txt10);

getContentPane().add(lbl12);
getContentPane().add(txt11);








//adjust the label to 5,5
lay.putConstraint(SpringLayout.WEST,lbl,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl,5,SpringLayout.NORTH,getContentPane());

//adjust the textfield to +5,5
lay.putConstraint(SpringLayout.WEST,txt,5,SpringLayout.EAST,lbl);
lay.putConstraint(SpringLayout.NORTH,txt,5,SpringLayout.NORTH,getContentPane());

//lbl1
lay.putConstraint(SpringLayout.WEST,lbl1,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl1,5,SpringLayout.SOUTH,lbl);

//txt1
lay.putConstraint(SpringLayout.WEST,txt1,5,SpringLayout.EAST,lbl1);
lay.putConstraint(SpringLayout.NORTH,txt1,5,SpringLayout.SOUTH,txt);

//lbl2
lay.putConstraint(SpringLayout.WEST,lbl2,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl2,5,SpringLayout.SOUTH,lb12);

//txt2
lay.putConstraint(SpringLayout.WEST,txt2,5,SpringLayout.EAST,lbl2);
lay.putConstraint(SpringLayout.NORTH,txt2,5,SpringLayout.SOUTH,txt);

//lbl3
lay.putConstraint(SpringLayout.WEST,lbl3,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl3,5,SpringLayout.SOUTH,lbl3);

//txt3
lay.putConstraint(SpringLayout.WEST,txt3,5,SpringLayout.EAST,lbl3);
lay.putConstraint(SpringLayout.NORTH,txt3,5,SpringLayout.SOUTH,txt);

//lbl4
lay.putConstraint(SpringLayout.WEST,lbl4,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl4,5,SpringLayout.SOUTH,lbl4);

//txt4
lay.putConstraint(SpringLayout.WEST,txt4,5,SpringLayout.EAST,lbl4);
lay.putConstraint(SpringLayout.NORTH,txt4,5,SpringLayout.SOUTH,txt);


//lbl5
lay.putConstraint(SpringLayout.WEST,lbl5,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl5,5,SpringLayout.SOUTH,lbl5);

//area
lay.putConstraint(SpringLayout.WEST,area(10,8),5,SpringLayout.EAST,lbl5);
lay.putConstraint(SpringLayout.NORTH,area(10,8),5,SpringLayout.SOUTH,area);


//lbl6
lay.putConstraint(SpringLayout.WEST,lbl6,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl6,5,SpringLayout.SOUTH,lbl6);

//txt5
lay.putConstraint(SpringLayout.WEST,txt5,5,SpringLayout.EAST,lbl6);
lay.putConstraint(SpringLayout.NORTH,txt5,5,SpringLayout.SOUTH,txt);

//lbl7
lay.putConstraint(SpringLayout.WEST,lbl7,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl7,5,SpringLayout.SOUTH,lbl7);

//txt6
lay.putConstraint(SpringLayout.WEST,txt6,5,SpringLayout.EAST,lbl7);
lay.putConstraint(SpringLayout.NORTH,txt6,5,SpringLayout.SOUTH,txt);

//lbl8
lay.putConstraint(SpringLayout.WEST,lbl8,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl8,5,SpringLayout.SOUTH,lbl8);

//txt7
lay.putConstraint(SpringLayout.WEST,txt7,5,SpringLayout.EAST,lbl8);
lay.putConstraint(SpringLayout.NORTH,txt7,5,SpringLayout.SOUTH,txt);

//lbl9
lay.putConstraint(SpringLayout.WEST,lbl9,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl9,5,SpringLayout.SOUTH,lbl9);

//txt8
lay.putConstraint(SpringLayout.WEST,txt8,5,SpringLayout.EAST,lbl9);
lay.putConstraint(SpringLayout.NORTH,txt8,5,SpringLayout.SOUTH,txt);

//lbl10
lay.putConstraint(SpringLayout.WEST,lbl10,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl10,5,SpringLayout.SOUTH,lbl10);

//txt9
lay.putConstraint(SpringLayout.WEST,txt9,5,SpringLayout.EAST,lbl10);
lay.putConstraint(SpringLayout.NORTH,txt9,5,SpringLayout.SOUTH,txt);

//lbl11
lay.putConstraint(SpringLayout.WEST,lbl11,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl11,5,SpringLayout.SOUTH,lbl11);

//txt10
lay.putConstraint(SpringLayout.WEST,txt10,5,SpringLayout.EAST,lbl1);
lay.putConstraint(SpringLayout.NORTH,txt10,5,SpringLayout.SOUTH,txt);

//lbl12
lay.putConstraint(SpringLayout.WEST,lbl12,5,SpringLayout.WEST,getContentPane());
lay.putConstraint(SpringLayout.NORTH,lbl12,5,SpringLayout.SOUTH,lbl12);

//txt11
lay.putConstraint(SpringLayout.WEST,txt11,5,SpringLayout.EAST,lbl12);
lay.putConstraint(SpringLayout.NORTH,txt11,5,SpringLayout.SOUTH,txt);
}
}






View Answers

September 24, 2010 at 2:45 PM

Hi Friend,

We have modified your code, try this:

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

class prog3 extends JFrame{
JLabel lbl,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lbl8,lbl9,lbl10,lbl11,lbl12;
JTextField txt,txt1,txt2,txt3,txt4,txt5,txt6,txt7,txt8,txt9,txt10,txt11;
JTextArea area;
SpringLayout lay;

public prog3(){
super("Employee Details");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(350,500);
setVisible(true);
widgets();
}
public static void main(String args[]){
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new prog3().setVisible(true);
}
});
}
public void widgets(){
lbl=new JLabel("Patient ID:");
txt=new JTextField(12);

lbl1=new JLabel("First Name:");
txt1=new JTextField(12);

lbl2=new JLabel("Last Name:");
txt2=new JTextField(12);

lbl3=new JLabel("Gender:");
txt3=new JTextField(12);

lbl4=new JLabel("Date Of Birth:");
txt4=new JTextField(12);

lbl5=new JLabel("Address:");
area=new JTextArea(4,12);

lbl6=new JLabel("Phone Number:");
txt5=new JTextField(12);

lbl7=new JLabel("Patient Occupation:");
txt6=new JTextField(12);

lbl8=new JLabel("Marital Status:");
txt7=new JTextField(12);

lbl9=new JLabel("Account Type:");
txt8=new JTextField(12);

lbl10=new JLabel("Company Name");
txt9=new JTextField(12);

lbl11=new JLabel("Age:");
txt10=new JTextField(12);

lbl12=new JLabel("Weight:");
txt11=new JTextField(12);

add(lbl);
add(txt);
add(lbl1);
add(txt1);
add(lbl2);
add(txt2);
add(lbl3);
add(txt3);
add(lbl4);
add(txt4);
add(lbl5);
add(area);
add(lbl6);
add(txt5);
add(lbl7);
add(txt6);
add(lbl8);
add(txt7);
add(lbl9);
add(txt8);
add(lbl10);
add(txt9);
add(lbl11);
add(txt10);
add(lbl12);
add(txt11);


lay=new SpringLayout();

September 24, 2010 at 2:47 PM

continue..

lay.putConstraint(SpringLayout.WEST,lbl,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl,10,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt,10,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl1,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl1,40,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt1,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt1,40,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl2,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl2,70,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt2,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt2,70,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl3,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl3,100,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt3,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt3,100,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl4,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl4,130,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt4,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt4,130,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl5,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl5,160,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,area,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,area,160,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl6,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl6,230,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt5,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt5,230,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl7,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl7,260,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt6,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt6,260,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl8,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl8,290,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt7,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt7,290,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl9,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl9,320,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt8,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt8,320,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl10,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl10,350,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt9,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt9,350,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl11,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl11,380,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt10,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt10,380,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,lbl12,10,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,lbl12,410,SpringLayout.NORTH,this);

lay.putConstraint(SpringLayout.WEST,txt11,150,SpringLayout.WEST,this);
lay.putConstraint(SpringLayout.NORTH,txt11,410,SpringLayout.NORTH,this);
setLayout(lay);
}
}
Thanks









Related Tutorials/Questions & Answers:
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
Advertisements
GUI framework
GUI framework  what do u mean by GUI framework
GUI component
GUI component  How can a GUI component handle its own events
Convert the code to GUI
GUI code  GUI code
gui question
gui question  design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
GUI problem
GUI problem  Create a class called CDProgram and write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest Rate: 7.75 Hint
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user entered value in first textfield(jtext1) and pressed the enter key . the cursor
Convert the code to GUI
GUI Example  GUI Example code to learn
Convert the code to GUI
GUI Application example  GUI Application example
Version of gj-gui>gj-gui dependency
List of Version of gj-gui>gj-gui dependency
Java GUI
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
GUI Application Development   GUI Application Development
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
gui question
gui question  design a gui application and write code to accept a string from the user in a textfeild and print using option pane whether it is a palindrome or not. hint: abba is a palindrome   import java.awt.*; import
GUI problem
GUI problem  How do I make a Jbutton which is shaped like a circle. This button needs to be clicked in order to change color.   import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
ModuleNotFoundError: No module named 'gui'
ModuleNotFoundError: No module named 'gui'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'gui' How to remove the ModuleNotFoundError: No module named 'gui' error
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Artifacts of gj-gui
List of Artifacts of gj-gui maven depenency
Maven Repository/Dependency: gj-gui | gj-gui
Maven Repository/Dependency of Group ID gj-gui and Artifact ID gj-gui. Latest version of gj-gui:gj-gui dependencies. # Version Release Date You can read more at: Maven Tutorials
Flex SDK GUI
Flex SDK GUI  Hi....... please give me ans of this question.. What classes do you typically extend in the Flex SDK for creating GUI controls and why? Thanks
GUI application program
GUI application program  Write a GUI application program that meets the following requirements: Create an array with 100 randomly chosen integers. Create a textfield to enter an array index and another textfield to display
Java GUI - Java3D
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Maven Dependency gj-gui >> 0.1
You should include the dependency code given in this page to add Maven Dependency of gj-gui >> gj-gui version0.1 in your project
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui application. I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui application. I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python... 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus-gui' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python... 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus-gui' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'argus-gui'
ModuleNotFoundError: No module named 'argus-gui'  Hi, My Python... 'argus-gui' How to remove the ModuleNotFoundError: No module named 'argus-gui' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'bottle-gui'
ModuleNotFoundError: No module named 'bottle-gui'  Hi, My Python... 'bottle-gui' How to remove the ModuleNotFoundError: No module named 'bottle-gui' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'bottle-gui'
ModuleNotFoundError: No module named 'bottle-gui'  Hi, My Python... 'bottle-gui' How to remove the ModuleNotFoundError: No module named 'bottle-gui' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'cadbiom-gui'
ModuleNotFoundError: No module named 'cadbiom-gui'  Hi, My Python... 'cadbiom-gui' How to remove the ModuleNotFoundError: No module named 'cadbiom-gui' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'checksum-gui'
ModuleNotFoundError: No module named 'checksum-gui'  Hi, My Python... 'checksum-gui' How to remove the ModuleNotFoundError: No module named 'checksum-gui' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'comemso-gui'
ModuleNotFoundError: No module named 'comemso-gui'  Hi, My Python... 'comemso-gui' How to remove the ModuleNotFoundError: No module named 'comemso-gui' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'ConfigObj-GUI'
ModuleNotFoundError: No module named 'ConfigObj-GUI'  Hi, My... 'ConfigObj-GUI' How to remove the ModuleNotFoundError: No module named 'ConfigObj-GUI' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dlc-gui'
ModuleNotFoundError: No module named 'dlc-gui'  Hi, My Python...-gui' How to remove the ModuleNotFoundError: No module named 'dlc-gui... to install padas library. You can install dlc-gui python with following command
ModuleNotFoundError: No module named 'eccw-gui'
ModuleNotFoundError: No module named 'eccw-gui'  Hi, My Python... 'eccw-gui' How to remove the ModuleNotFoundError: No module named 'eccw-gui... to install padas library. You can install eccw-gui python with following
ModuleNotFoundError: No module named 'giwaxs-gui'
ModuleNotFoundError: No module named 'giwaxs-gui'  Hi, My Python... 'giwaxs-gui' How to remove the ModuleNotFoundError: No module named 'giwaxs-gui' error? Thanks   Hi, In your python environment you

Ads