Graphical user interface (GUI)

Graphical user interface (GUI)
Graphical user interface (GUI),technical hassan ali

Syntax:
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.awt.Color;
class test{
	public static void main(String [] args){
	JFrame frame = new JFrame();
	ImageIcon image = new ImageIcon("1.jpg");
	frame.setTitle("Hassan Ali");            //Set the Title of JFrame
	frame.setSize(420,420);                 // Set the X-Dimenstional and Y-Dimentional
	frame.setResizable(false);              // Pretent Being the Resize Not Resize
	frame.setVisible(true);                 // It will make visible very Small
	frame.setIconImage(image.getImage());   //change icon of the Frame
	frame.getContentPane().setBackground(Color.green); // Change the Background Color
	frame.getContentPane().setBackground(new Color(123,50,250)); // Change the Background Color
	}
 }

GUI SWING JFrame
import javax.swing.*;
import java.awt.*;
class javaFrame{
	public static void main(String [] args){
		JFrame frame = new JFrame();  // Using For frame
		//setVisible show the Frame
		frame.setVisible(true);
		//SetSize is the set size in width x Height
		frame.setSize(500,500);
		//setDefaultCloseOperation is used for close the frame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//setLocation is used to set location left , top of the frame
		frame.setLocation(200,50);
		//setBound is used for the setSize and setLocation of Frame
		//setBound(left_size,right_size, width, Height)
		frame.setBounds(200,50,500,700);
		//For Set the Title of Frame use
		frame.setTitle("Hassan Ali");
		/*Disable Resizeable in the Frame
		frame.setResizable(false);*/
		}
}

GUI SetIcon on Top JFrame
JFrame frame = new JFrame();
frame.setVisible(true);

//Set Icon Top Bar
ImageIcon image = new ImageIcon("logo.png");
frame.setIconImage(image.getImage());

GUI JContainer Background JFrame
/*Changing the background Color of the Frame */
Container con = frame.getContentPane();
con.setBackground(Color.green);
con.setLayout(null);

GUI JLabel
//Creating Label for show Label in frame
		JLabel label = new JLabel("Username");
		//setBounds is used for change the size left x top x width x height
		label.setBounds(100,50,200,30);
		//setText is used to Set the text in Label
		label.setText("Password");
		con.add(label);

GUI Font on JFrame
/*Creating Object of Class Font
		Font f = new Font("Name of Font",Font.PLAIN/BOLD/ITALIC,Font_size);*/
		Font f = new Font("Time New Roman",Font.BOLD,20);
		//Set Font on Label
		label.setFont(f);

GUI JTextField
//Adding Text Field
		JTextField t = new JTextField(); //Ading TextField Object
		t.setBounds(100,80,200,30);      //setBounds(left,top,width,height);
		t.setFont(f);                   //set fonts
		con.add(t);                    //Ading
		t.setBackground(Color.YELLOW); //Change background of TextField
		t.setForeground(Color.RED);    //Change font color
       //Creating for RGB Color
		Color c = new Color(50,50,50);
		//t.setBackground(c);

GUI JFrame Password
JPasswordField password = new JPasswordField();
		password.setBounds(100,200,200,30);
		password.setFont(f);
		password.setBackground(c);
		password.setForeground(Color.WHITE);
		con.add(password);

GUI JFrame Button
//Set image in button
		ImageIcon image1 = new ImageIcon("logo.png");
		JButton button = new JButton(image1);
		button.setBounds(100,240,image1.getIconWidth(),image1.getIconHeight());
		button.setFont(f);
		con.add(button);

Post a Comment

Post a Comment (0)

Previous Post Next Post