Swing (Jbutton, Jlabel ) Awt (Button, Label ) : Java Gui
Swing (Jbutton, Jlabel ) Awt (Button, Label ) : Java Gui
Button Color
Frame
Radio Font
Textfield …. panel event…
b.setTitle("mustapha");
b.setSize(300, 200);
b.setVisible(true);
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setResizable(false);
JFrame in Constructor :
public class j2 extends JFrame {
public j2(){
this.SetTitle("frame2");
this.setSize(new Dimension(500,300));
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(100, 100);
JFrame in classe :
public void show(){
this.SetTitle("sss");
this.SetSize("500,250");
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(100, 100);
JPanel:
public class jgui extends JFrame {
public jgui() {
kj();
setTitle("frame2");
setSize(new Dimension(500,300));
setResizable(false);
setVisible(true);
add(n);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
n.setBackground(Color.RED);
}
Add button:
setLayout(new FlowLayout());
add(b1);
add(b2);
add(f1);
panel
frame
button
Textfield
Layout:
GridLayout:
setLayout(new GridLayout(2,6,10,30));
BorderLayout:
setLayout(new BorderLayout(10,20));
add(b1,BorderLayout.EAST);
add(b2,BorderLayout.NORTH);
add(b3,BorderLayout.SOUTH);
add(b4,BorderLayout.WEST);
AbsoluteLayout(x,y,w,h):
setLayout(null);
b1.setBounds(100,10,200,200);
add(b1);
Y
X
W H
Add button in a frame:
P1.add(b1);
New project:
File Edit Help
Full name :
Password :
Single in a relationship
Material : CG CA SA DB
Menu
JMenu JMenuBar
CODE :
package gradleproject1;
import java.awt.*;
import javax.swing.*;
JPanel p1,p2,p3;
JLabel l1,l2,l3,l4,l5;
JTextField t1;
JPasswordField t2;
JButton b1,b2,n1,n2,n3,n4,n5;
JRadioButton r1,r2,r3,r4,r5;
ButtonGroup G1,G2;
JCheckBox ch1,ch2,ch3,ch4;
JMenu m1,m2,m3;
JMenuBar mb1;
public login() {
this.setTitle("form");
this.setVisible(true);
this.setSize(500, 700);
this.setLocation(200, 50);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setLayout(null);
l2=new JLabel("Password:");
l4=new JLabel("status:");
this.add(l1);
this.add(t1);
this.add(l2);
this.add(t2);
this.add(b1);
this.add(b2);
this.add(l3);
G1.add(r1);
G1.add(r2);
G1.add(r3);
this.add(l4);
G2.add(r4);
G2.add(r5);
this.add(r1);
this.add(r2);
this.add(r3);
this.add(r4);
this.add(r5);
this.add(l5);
n5.setBackground(Color.red);
n4.setBackground(Color.BLUE);
n3.setBackground(Color.BLUE);
n2.setBackground(Color.GREEN);
n1.setBackground(Color.GREEN);
n1.setForeground(Color.DARK_GRAY);
n2.setForeground(Color.DARK_GRAY);
n3.setForeground(Color.YELLOW);
n4.setForeground(Color.YELLOW);
n5.setForeground(Color.white);
this.add(ch1);
this.add(ch2);
this.add(ch3);
this.add(ch4);
m1.add(n5);
m2.add(n1);
m2.add(n2);
m3.add(n3);
m3.add(n4);
mb1.add(m1);
mb1.add(m2);
mb1.add(m3);
this.add(mb1); }
EVENTS:
ActionListener ActionEvent
ssss
Code:
package event;
import java.awt.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.* ;
}
@Override
public void itemStateChanged(ItemEvent e) {
if (c1.isSelected()&& c2.isSelected()&& c3.isSelected()){
l3.setFont(new Font("atilic",Font.BOLD+Font.ITALIC+Font.PLAIN,y));
}
else if(c1.isSelected()) {
l3.setFont(new Font("atilic",Font.BOLD,y));
}
else if (c2.isSelected()){
l3.setFont(new Font("atilic",Font.ITALIC,y));
}
else if (c3.isSelected()){
l3.setFont(new Font("atilic",Font.PLAIN,y));
}
else if (c2.isSelected()&& c1.isSelected()){
l3.setFont(new Font("atilic",Font.ITALIC+Font.BOLD,y));
}
else if (c3.isSelected()&& c1.isSelected()){
l3.setFont(new Font("atilic",Font.PLAIN+Font.BOLD,y));
}
else if (c2.isSelected()&& c3.isSelected()){
l3.setFont(new Font("atilic",Font.ITALIC+Font.PLAIN,y));
}
}
}
if (e.getSource()==b2){
s1=t1.getText();
s2=t2.getText();
t3.setText(s1+" " +s2);
l3.setText("welcome"+" "+s1);
t1.setText(" ");
t2.setText(" ");
}
if (e.getSource()==r1){
p2.setBackground(Color.red);
t3.setForeground(Color.red);
l3.setForeground(Color.PINK);
}
if (e.getSource()==r2){
p2.setBackground(Color.BLUE);
t3.setForeground(Color.BLUE);
l3.setForeground(Color.BLUE);
}
if (e.getSource()==r3){
p2.setBackground(Color.YELLOW);
t3.setForeground(Color.YELLOW);
l3.setForeground(Color.yellow);
}
if (e.getSource()==r4){
p2.setBackground(Color.GREEN);
t3.setForeground(Color.GREEN);
l3.setForeground(Color.GREEN);
}
if (e.getSource()==r5){
p2.setBackground(Color.GRAY);
t3.setForeground(Color.GRAY);
l3.setForeground(Color.GRAY);
}
if (e.getSource()==b3){
x+=10;
l3.setBounds(x, 10, 300, 50);
}
if (e.getSource()==b4){
x-=10;
l3.setBounds(x, 10, 300, 50);
}
if (e.getSource()==b5){
y-=2;
l3.setFont(new Font("atilic",Font.CENTER_BASELINE,y));
}
if (e.getSource()==b6){
y+=2;
l3.setFont(new Font("atilic",Font.CENTER_BASELINE,y));
}
}
}
}
package event;
}
Mouse Event:
package mouse;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class me extends JFrame {
JPanel p1,p2;
JLabel l1,l2;
nm n= new nm();
public me(){
this.setSize(300,500);
this.setTitle("M_Event");
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(2,1));
p2.setBackground(Color.BLUE);
p1.setBackground(Color.RED);
this.add(p1);
this.add(p2);
p1.setLayout(null);
p2.setLayout(null);
l2.setForeground(Color.MAGENTA);
l1.setForeground(Color.WHITE);
p1.add(l1);
p2.add(l2);
p1.addMouseListener(n);
p2.addMouseListener(n);
p2.addMouseMotionListener(n);
@Override
p2.setBackground(Color.CYAN);
l2.setText("Mouse Clicked");
@Override
@Override
@Override
l1.setText("Mouse Entered");
p1.setBackground(Color.GREEN);
@Override
l1.setText("Mouse Exited");
p1.setBackground(Color.RED);
@Override
@Override
@Override
me m= new me();