java.lab
java.lab
package ajaybca;
import javax.swing.*;
public class NewMain {
public static void main(String[] args) {
JFrame f=new JFrame();
f.setTitle("1st Frame");
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
2)Textdemo
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class Textdemo extends JFrame {
public Textdemo(){
setTitle("First Frame");
setSize(300,300);
setLayout(null);
repaint();
setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
g.drawString("Welcome to Strings", 50, 50);
}
public static void main(String[] args) {
Textdemo f=new Textdemo();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
3)LABELIMAGE
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class labelimage {
public static void main(String[] args) {
JFrame f=new JFrame();
f.setTitle("First Frame");
f.setSize(300, 300);
f.setLayout(new FlowLayout());
ImageIcon i=new
ImageIcon("C:\\Users\\my.ac.u3bca23206\\Downloads\\vlzg1js1jbz71.jpg");
JLabel label=new JLabel("ABC Pvt Ltd",i,JLabel.CENTER);
f.add(label);
f.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
4)ANIMALS
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class labelimage {
public static void main(String[] args) {
JFrame f=new JFrame();
f.setTitle("First Frame");
f.setSize(300, 300);
f.setLayout(new FlowLayout());
ImageIcon i1=new
ImageIcon("C:\\Users\\my.ac.u3bca23206\\Downloads\\1istockphoto-1356481088-61
2x612.jpg");
ImageIcon i2=new
ImageIcon("C:\\Users\\my.ac.u3bca23206\\Downloads\\2istockphoto-1356481088-61
2x612.jpg");
JLabel label=new JLabel ("Animals");
label.setBounds(10,50,100,40);
JLabel label1=new JLabel("EAGLE",i1,JLabel.CENTER);
label.setBounds(10,50,100,40);
JLabel label2=new JLabel("LION",i2,JLabel.CENTER);
label.setBounds(150,50,100,40);
f.add(label);
f.add(label1);
f.add(label2);
f.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
5)JPANEL
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class jpanel {
public static void main(String[] args) {
JFrame frame = new JFrame("JPanel Example");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(null);
frame.add(panel);
frame.setVisible(true);
}
}
6)JTEXTFIELD
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class jtf {
public static void main(String[] args) {
JFrame frame = new JFrame("Jtextfield demo");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
JTextField textField = new JTextField();
textField.setBounds(50,50,200,30);
textField.setText("Enter your Name");
frame.add(textField);
frame.setVisible(true);
}
}
7)JLABEL PRGM
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class frmprg {
frmprg(){
JFrame f = new JFrame("JLabel Prg Example");
JLabel l1 = new JLabel("1stName");
l1.setBounds(100,100,150,50);
f.add(l1);
f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new frmprg();
}
8)JBUTTON
package ajaybca;
import java.awt.*;
import javax.swing.*;
public class jb {
jb(){
JFrame f = new JFrame("JButton Eg");
JButton b1 = new JButton("Add");
b1.setBounds(100,100,150,50);
f.add(b1);
f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new jb();
}
9)ADD
package ajaybca;
import javax.swing.*;
import java.awt.event.*;
add() {
setSize(500, 500);
setLayout(null);
b = new JButton("Add");
b.setBounds(130, 130, 100, 30);
add(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int num1 = Integer.parseInt(tf1.getText());
int num2 = Integer.parseInt(tf2.getText());
int sum = num1 + num2;
l3.setText("Result: " + sum);
} catch (NumberFormatException ex) {
l3.setText("Invalid input");
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
TEXTAREA
package ajaybca;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
frame.add(new JScrollPane(textArea));
frame.add(button);
frame.add(label);
frame.setVisible(true);
}
}