import javax.swing.*;
class ButtonTextFieldLabel extends JFrame{
JButton bnt1,bnt2,bnt3;
JTextField tf;
JLabel lbl;
public ButtonTextFieldLabel(){
super("Hello");
//create a text box, a label and 3 buttons objects
tf=new JTextField("TextField");
lbl=new JLabel("Label");
bnt1=new JButton("Button1");
bnt2=new JButton("Button2");
bnt3=new JButton("Button3");
setLayout(null);/*setting the layout of displaying controls to null
will enable you to specify the locations of your controls to display
*/
//set specific locations of the controls by using setBounds() method
tf.setBounds(150,300,60,40);//x=90,y=100,width=60,height=40
lbl.setBounds(150,150,80,40);
bnt1.setBounds(50,200,80,40);
bnt2.setBounds(150,200,80,40);
bnt3.setBounds(250,200,80,40);
//add controls on the JFrame
add(tf);
add(lbl);
add(bnt1);
add(bnt2);
add(bnt3);
add(tf);
setSize(500,500);
setVisible(true);}
}
public class TestBTL{
public static void main(String[] args){
new ButtonTextFieldLabel();
}
}
![]() Vishakha Sonawane This is awsome 2016-12-12 |
|
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.