JFrame & JLable
Code : -
// 1 - JFrame
// 2 - JLabel
// 3 - FlowLayout - basic
JLabel background=new JLabel();
background.setLocation(150,150);
background.setBackground(Color.black);
background.setOpaque(true);
background.setSize(250,250);
JLabel heading =new JLabel("Details"); // YOu can also use setText function for set Text
heading.setForeground(Color.black); // Change the Text Color
heading.setBackground(Color.white);
heading.setOpaque(true);
heading.setHorizontalAlignment(JLabel.CENTER);
//heading.setText();
heading.setSize(250,40);
//----------------------Name-------------------
JLabel name = new JLabel();
name.setBackground(Color.white);
name.setOpaque(true);
name.setForeground(Color.black);
name.setText("Name");
name.setSize(50,20);
name.setLocation(20,60); // Set Margin
name.setHorizontalAlignment(JLabel.CENTER);
// JTextArea , JTextFiled , BoxLayout , GridLayout , JPanel
JLabel jLabel_name=new JLabel("Chotu");
jLabel_name.setLocation(160,60); // Like = Margin
jLabel_name.setSize(50,20);
jLabel_name.setForeground(Color.black);
jLabel_name.setBackground(Color.white);
jLabel_name.setOpaque(true);
jLabel_name.setHorizontalAlignment(JLabel.CENTER);
//--------------------Age------------------
JLabel age=new JLabel("Age");
age.setLocation(20,110);
age.setSize(50,20);
age.setForeground(Color.black);
age.setBackground(Color.white);
age.setOpaque(true);
age.setHorizontalAlignment(JLabel.CENTER);
JLabel num=new JLabel("30");
num.setLocation(160,110);
num.setSize(50,20);
num.setForeground(Color.black);
num.setBackground(Color.white);
num.setOpaque(true);
num.setHorizontalAlignment(JLabel.CENTER);
//--------------Gender---------------
JLabel gender=new JLabel("Gender");
gender.setLocation(20,160);
gender.setSize(50,20);
gender.setForeground(Color.black);
gender.setBackground(Color.white);
gender.setOpaque(true);
gender.setHorizontalAlignment(JLabel.CENTER);
JLabel male=new JLabel("Male");
male.setLocation(160,160);
male.setSize(50,20);
male.setForeground(Color.black);
male.setBackground(Color.white);
male.setOpaque(true);
male.setHorizontalAlignment(JLabel.CENTER);
//------------------Salary---------------
JLabel salary=new JLabel("Salary");
salary.setLocation(20,210);
salary.setSize(50,20);
salary.setForeground(Color.black);
salary.setBackground(Color.white);
salary.setOpaque(true);
salary.setHorizontalAlignment(JLabel.CENTER);
JLabel value=new JLabel("25,000");
value.setLocation(160,210);
value.setSize(50,20);
value.setForeground(Color.black);
value.setBackground(Color.white);
value.setOpaque(true);
value.setHorizontalAlignment(JLabel.CENTER);
background.add(heading);
background.add(name);
background.add(jLabel_name);
background.add(age);
background.add(num);
background.add(gender);
background.add(male);
background.add(salary);
background.add(value);
JFrame jFrame=new JFrame();
jFrame.setSize(500,500);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setLayout(null);
jFrame.add(background);
jFrame.setVisible(true);
Comments
Post a Comment