July 24, 2012 at 10:51 AM
The setBounds() method sets the position of swing components on the container i.e. on JFrame. Here is a simple login form code that sets the textfields, button and labels on the frame using setBounds() method.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class LoginDemo extends JFrame{
JButton SUBMIT;
JLabel label1,label2,lab;
final JTextField text1,text2;
LoginDemo(){
setTitle("Login Form");
setLayout(null);
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
SUBMIT=new JButton("SUBMIT");
label1.setBounds(350,100,100,20);
text1.setBounds(450,100,200,20);
label2.setBounds(350,130,100,20);
text2.setBounds(450,130,200,20);
SUBMIT.setBounds(450,160,100,20);
add(label1);
add(text1);
add(label2);
add(text2);
add(SUBMIT);
setVisible(true);
setSize(1024,768);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
JOptionPane.showMessageDialog(null,"Hello "+value1);
}
});
}
public static void main(String arg[]){
new LoginDemo();
}
}
Related Tutorials/Questions & Answers:
Java QueriesJava Queries How to use setBounds() method in
Java GUI application??
The setBounds() method sets the position of swing components on the container i.e. on JFrame. Here is a simple login form code that sets
3 queries on java class3
queries on
java class Hey.
I need to do 3
queries on same class (
JAVA)
One is to populate the combobox, the another one to populate tje jlist and the last one to use on button to open a file from database (BLOB)
Can some
Advertisements
to add on to my queries - Java Beginnersto add on to my queries
Dear Experts,
Sorry but I am worried that I did not explain clearly so I am adding in the error message I get from Netbean IDE when I run that
queries using the last solution provided.
I'm puzzled
Execute SQL Queries with Java Application
Execute SQL
Queries with
Java Application
This is detailed
java program to connect
java application and execute
queries
like create table in mysql database, insert some
datatypes queriesdatatypes queries Respected sir ,what is the reason behind that
java compiler gives me an error when float datatype isused to store float value?why we prefered double datatype for this?
You can use Scanner class
ModuleNotFoundError: No module named 'queries'ModuleNotFoundError: No module named '
queries' Hi,
My Python... '
queries'
How to remove the ModuleNotFoundError: No module named '
queries... to install padas library.
You can install
queries python with following command