Fukte Runner
Fukte Runner
VJTechSoft() {
// Set layout and colors
setLayout(null);
setBackground(Color.orange);
setForeground(Color.black);
L6 = new Label();
L6.setForeground(Color.red);
// Set bounds for "Enter Address" label and TextArea for address
L16.setBounds(100, 650, 150, 40); // "Enter Address" label
taAddress.setBounds(300, 650, 300, 80); // TextArea for address
StudentRegistrationForm() {
setLayout(null);
setBackground(Color.lightGray);
setForeground(Color.black);
add(L1);
add(L2);
add(tfName);
add(L3);
add(male);
add(female);
add(L4);
add(tfMobile);
add(L5);
add(chDepartment);
add(L6);
add(lstSubjects);
add(submitButton);
add(resultLabel);
}
Ans.
import java.awt.*;
import javax.swing.*;
class seasonslist extends JFrame
{
seasonslist()
{
Container c=getContentPane();
setLayout(new FlowLayout());
String str[]={"summer","winter","rainy"};
JList j1=new JList(str);
c.add(j1);
}
public static void main(String args[])
{
seasonslist s=new seasonslist();
s.setVisible(true);
s.setSize(500,500);
s.setTitle("subjects");
s.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
Ans.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class subject extends JFrame
{
JComboBox cb;
subject()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
String str[]={"Maths","Physics","Chemistry","Java","c+
+","javascript","php","python","ajp","c"};
cb=new JComboBox(str);
c.add(cb);
}
public static void main(String args[])
{
subject s=new subject();
s.setVisible(true);
s.setSize(500,500);
s.setTitle("subjects");
s.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
c.add("a",b1);
c.add("b",b2);
c.add("c",b3);
c.add("d",b4);
c.add("e",b5);
}
public void actionPerformed(ActionEvent e)
{
card.next(c);
}
public static void main(String args[])
{
CardLayoutExample c1=new CardLayoutExample();
c1.setVisible(true);
c1.setSize(400,400);
c1.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public MenuBarExample()
{
MenuBar = new MenuBar();
Menu fileMenu = new Menu("File");
MenuItem newItem = new MenuItem("New");
MenuItem openItem = new MenuItem("Open");
fileMenu.add(newItem);
fileMenu.add(openItem);
menuBar.add(fileMenu );
Menu editMenu = new Menu("Edit");
menuBar.add(editMenu);
Menu viewMenu = new Menu("View");
menuBar.add(viewMenu);
setMenuBar(menuBar);
}
public static void main(String[] args)
{
MenuBarExample me=new MenuBarExample();
me.setTitle("AWT MenuBar Example");
me.setSize(400, 300);
me.setVisible(true);
}
}
greenItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel.setBackground(Color.GREEN);
}
});
blueItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel.setBackground(Color.BLUE);
}
});
setLayout(null);
add(label);
add(comboBox);
add(scrollPane);
}
}
Q.8]
i) Write a program to develop frame to select the different states of
India using JComboBox
Ans.
import javax.swing.*;
import java.awt.*;
public class ComboboxDemoDemo extends JFrame
{
JComboBox jc;
ComboboxDemoDemo()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
String state[]={"Maharashtra", "Gujrat", "Delhi", "Rajsthan","Asam","Andhra
Pradesh","Arunachal Pradesh","Bihar","Chattisgadh","goa","Haryana","Himachal
Pradesh","Zarkhand","Karnataka","Kerala","Madhya
Pradesh","Manipur","Meghalaya","Mizoram","Nagaland","Odisha","Panjab","Sikkim","Tamil
nadu","Telangana","Tripura","Uttar Pradesh"};
jc = new JComboBox<>(state);
c.add(jc);
}
public static void main(String args[])
{
ComboboxDemoDemo cb =new ComboboxDemoDemo();
cb.setVisible(true);
cb.setSize(400,400);
cb.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
ii) Develop a program to demonstrate the use of ScrollPane in swings
Ans.
import javax.swing.*;
import java.awt.*;
frame.add(scrollPane);
frame.setVisible(true);
}
}
}
public static void main(String args[]) {
demoJTreePract6 f1 = new demoJTreePract6();
f1.setVisible(true);
f1.setSize(600, 600);
f1.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
Ans.
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class demoJTreePract6 extends JFrame
{
demoJTreePract6()
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
}
public static void main(String args[]) {
demoJTreePract6 f1 = new demoJTreePract6();
f1.setVisible(true);
f1.setSize(600, 600);
f1.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
JTableDemo() {
Container c = getContentPane();
c.setLayout(null);
l1 = new JLabel("Name:");
l2 = new JLabel("Age:");
l3 = new JLabel(" ");
b1 = new JButton("Add");
b1.setBounds(100, 250, 200, 40);
l3.setBounds(100, 280, 200, 40);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(b1);
c.add(tf1);
c.add(tf2);
// Setting up table
String colName[] = {"Name", "Age"};
model = new DefaultTableModel(null, colName); // Initially no data
t1 = new JTable(model);
JScrollPane js = new JScrollPane(t1);
js.setBounds(100, 500, 400, 100);
c.add(js);
b1.addActionListener(this);
}
if (ae.getSource() == b1) {
// Add data to the table model
model.addRow(new Object[]{name, age});
l3.setText("Successfully added");
tf1.setText("");
tf2.setText("");
}
}
Q.12]
i) Write a program to launch a progressBar
Ans.
import java.awt.*;
import javax.swing.*;
JProgressBarDemo() {
Container c = getContentPane();
c.setLayout(null);
c.setBackground(Color.orange);
try {
Thread.sleep(150); // Delay for smoother progress
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
JProgressBarBtn() {
Container c = getContentPane();
c.setLayout(null);
c.setBackground(Color.orange);
// Initialize button
showProgressButton = new JButton("Show Progress");
showProgressButton.setBounds(200, 300, 200, 40);
try {
Thread.sleep(150); // Delay for smoother progress
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
MultiplyDemo() {
// Frame setup
setLayout(null);
setBackground(Color.cyan); // Correct syntax
t1 = new TextField();
t2 = new TextField();
t3 = new TextField();
t3.setEditable(false); // Result field should not be editable
b1 = new Button("Multiply");
// Frame settings
setTitle("Multiplication Demo");
setSize(500, 400);
setVisible(true);
// Close operation
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// Main method
public static void main(String[] args) {
new MultiplyDemo();
}
}
}
public void actionPerformed(ActionEvent ae)//Event
{
String un=tf1.getText();
String psw=tf2.getText();
if(un.equals("KARAN") && psw.equals("KARAN"))
{
vj.setText("Login Successful!!!");
}
else
{
vj.setText("Login Fail!!!");
}
}
public static void main(String args[])
{
LoginPage2 lp=new LoginPage2();
lp.setVisible(true);
lp.setTitle("Login Page");
lp.setSize(700,700);
}
}