[go: up one dir, main page]

0% found this document useful (0 votes)
34 views15 pages

AJP

Ajp programs

Uploaded by

yadnyabothe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views15 pages

AJP

Ajp programs

Uploaded by

yadnyabothe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1) & 4)

import java.awt.*;

public class practice

public static void main(String args[])

Frame f = new Frame();

GridLayout obj = new GridLayout(5,5);

Label l = new Label("Enter name : ");

TextField tf = new TextField("Your name");

TextArea ta = new TextArea("Tell me about your education ");

Checkbox c1 = new Checkbox("C++");

Checkbox c2 = new Checkbox("Python");

CheckboxGroup cbg = new CheckboxGroup();

Checkbox r1 = new Checkbox("Female",cbg,false);

Checkbox r2 = new Checkbox("Male",cbg,false);

Button b = new Button("Submit");

f.add(l);

f.add(tf);

f.add(ta);

f.add(c1);

f.add(c2);

f.add(r1);

f.add(r2);

f.setVisible(true);

f.setSize(400,400);

f.setTitle("Practical");

f.setLayout(obj);

}
2)

import java.awt.*;

public class practice

public static void main(String args[])

Frame f = new Frame();

GridLayout obj = new GridLayout(5,5);

Button b1 = new Button("Ok");

Button b2 = new Button("CANCEL");

Button b3 = new Button("RETRY");

f.add(b1);

f.add(b2);

f.add(b3);

f.setVisible(true);

f.setSize(400,400);

f.setTitle("Practical");

f.setLayout(obj);

}
3)

import java.awt.*;

public class practice

public static void main(String args[])

Frame f = new Frame();

FlowLayout obj = new FlowLayout();

List l = new List(3);

l.add("Flowers");

l.add("Travel");

l.add("Sky");

f.add(l);

Choice c = new Choice();

c.add("Disneyland");

c.add("Korea");

f.add(c);

f.setVisible(true);

f.setSize(400,400);

f.setTitle("Practical");

f.setLayout(obj);

6)

import java.awt.*;

public class practice

{
public static void main(String args[])

Frame f = new Frame();

MenuBar mb = new MenuBar();

f.setMenuBar(mb);

Menu a = new Menu("File");

Menu b = new Menu("Edit");

Menu c = new Menu("Save");

mb.add(a);mb.add(b);mb.add(c);

MenuItem sub1 = new MenuItem("New");

MenuItem sub2 = new MenuItem("Open");

a.add(sub1);

a.addSeparator();

a.add(sub2);

f.setVisible(true);

f.setSize(400,400);

f.setTitle("Practical");

f.setLayout(null);

}
5)

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class CardLayoutExample extends JFrame implements ActionListener {

private JButton button1, button2, button3;

private CardLayout cardLayout;

private JPanel mainPanel, panel1, panel2, panel3;

public CardLayoutExample() {

super("Card Layout Example");

// Initialize CardLayout and set it as the layout for mainPanel

cardLayout = new CardLayout();

mainPanel = new JPanel(cardLayout);

// Create panels

panel1 = new JPanel();

panel2 = new JPanel();

panel3 = new JPanel();

// Create buttons

button1 = new JButton("Go to Panel 2");

button2 = new JButton("Go to Panel 3");

button3 = new JButton("Go to Panel 1");

// Add buttons to panels

panel1.add(button1);

panel2.add(button2);

panel3.add(button3);
// Add panels to the mainPanel (CardLayout container)

mainPanel.add(panel1);

mainPanel.add(panel2);

mainPanel.add(panel3);

// Add action listeners to buttons

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

// Add mainPanel to the frame

add(mainPanel);

// Frame settings

setSize(300, 300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

@Override

public void actionPerformed(ActionEvent e) {

// Navigate to the next panel

cardLayout.next(mainPanel);

public static void main(String[] args) {

new CardLayoutExample();

}
7)

import java.awt.FlowLayout;

import javax.swing.*;

public class practice extends JApplet {

public void init()

setLayout(new FlowLayout());

String arr[] = {"English","Marathi","Hindi","Sanskrit"};

JComboBox<String> cb = new JComboBox<>(arr);

add(cb);

<html>

<body>

<applet code="practice" width="300" height="150"></applet>

</body>

</html>
8)

import javax.swing.*;

import javax.swing.tree.DefaultMutableTreeNode;

public class practice {

JFrame f;

practice(){

f=new JFrame();

DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style");

DefaultMutableTreeNode color=new DefaultMutableTreeNode("color");

DefaultMutableTreeNode font=new DefaultMutableTreeNode("font");

DefaultMutableTreeNode texture = new DefaultMutableTreeNode("Texture");

style.add(color);

style.add(font);

style.add(texture);

DefaultMutableTreeNode red=new DefaultMutableTreeNode("red");

DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");

DefaultMutableTreeNode black=new DefaultMutableTreeNode("black");

DefaultMutableTreeNode green=new DefaultMutableTreeNode("green");

color.add(red); color.add(blue); color.add(black); color.add(green);

JTree jt=new JTree(style);

f.add(jt);

f.setSize(200,200);

f.setVisible(true);

public static void main(String[] args) {

new practice();

}}
9)

import javax.swing.*;

public class practice {

practice(){

JFrame f=new JFrame();

String data[][] = {{"1","Nidhi","90"},

{"2","Vidhi","95"}};

String cols[]={"RollNo","Name","Marks"};

JTable jt = new JTable(data,cols);

jt.setBounds(20,30,100,100);

f.add(jt);

f.setSize(500,500);

f.setVisible(true);

public static void main(String[] args) {

new practice();

}}
10)

import javax.swing.*;

public class practice {

public static void main(String[] args) {

// Create a JFrame

JFrame frame = new JFrame("JProgressBar Example");

frame.setSize(300, 100);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setLayout(null);

// Create a JProgressBar

JProgressBar progressBar = new JProgressBar(0, 100);

progressBar.setBounds(50, 30, 200, 20); // Set position and size

progressBar.setStringPainted(true); // Display progress as a string

frame.add(progressBar);

// Show the frame

frame.setVisible(true);

// Increment the progress bar in a loop

for (int i = 0; i <= 100; i++) {

try {

Thread.sleep(50); // Pause for 50 milliseconds

progressBar.setValue(i); // Update progress bar value

} catch (InterruptedException e) {

e.printStackTrace();

}
12)

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class practice extends JFrame implements ActionListener {

JLabel l;

practice() {

l = new JLabel();

JButton b = new JButton("Display");

b.setBounds(20, 20, 100, 50);

l.setBounds(50, 100, 100, 40);

// Add action listener to the button

b.addActionListener(this); // Use 'this' to refer to the class's actionPerformed

add(b);

add(l);

setSize(300, 300);

setLayout(null); // Set layout to null for absolute positioning

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Ensure the program exits on close

@Override

public void actionPerformed(ActionEvent e) {

l.setText("Hello..");
}

public static void main(String args[]) {

new practice(); // Create an instance of the practice class

13)

import java.awt.*;

import java.awt.event.*;

public class practice extends Frame implements MouseListener

Label l;

practice()

addMouseListener(this);

l = new Label();

l.setBounds(30,30,100,50);

add(l);

setSize(300,300);

setVisible(true);

setLayout(null);

public void mouseClicked(MouseEvent e) {

l.setText("Mouse Clicked");

public void mousePressed(MouseEvent e) {

l.setText("Mouse Pressed");

}
public void mouseReleased(MouseEvent e) {

l.setText("Mouse Released");

public void mouseEntered(MouseEvent e) {

l.setText("Mouse Entered");

public void mouseExited(MouseEvent e) {

l.setText("Mouse Exited");

public static void main(String args[])

new practice();

}
14)

import javax.swing.*;

public class practice extends JFrame

practice()

JTextField jt = new JTextField("Enter anything");

jt.setBounds(20,20,100,10);

add(jt);

setSize(400,400);

setVisible(true);

setLayout(null);

public static void main(String args[])

new practice();

15)

import java.awt.*;

import java.awt.event.*;

class practice extends WindowAdapter{

Frame f;

Label l;

practice(){

f=new Frame("Window Adapter");


l = new Label("if clicked on the close button then it will close the window using window
adapter");

f.add(l);

f.setSize(300,300);

f.setVisible(true);

f.addWindowListener(this);

public void windowClosing(WindowEvent e){

f.dispose();

public static void main(String[] args) {

new practice();

16)

You might also like