Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Showing posts with label FIFTH WEEK LAB PROGRAM. Show all posts
Showing posts with label FIFTH WEEK LAB PROGRAM. Show all posts

Saturday, 23 February 2019

Fifth Week Term Work Program 4


Question









Program:


import java.awt.*;
import java.awt.event.*;

public class Registrationform {
public static void main(String[] args) {
Frame f = new RegistrationFrame("Registration Form");
f.setSize(260, 200);
f.setVisible(true);
}
}
//Frame class
class RegistrationFrame extends Frame {
public RegistrationFrame(String title) {
super(title);
setLayout(null);
setBackground(Color.white);
Label l1=new Label("Enter your name:");
l1.setBounds(10, 40, 120, 50);
Label l2=new Label("Enter your Mobile no:");
l2.setBounds(10, 70, 120, 50);
add(l1);
add(l2);
TextField t1=new TextField();
t1.setEditable(true);
t1.setBounds(130, 55, 100, 20);
TextField t2=new TextField();
t2.setBounds(130, 85, 100, 20);
t2.setEditable(true);
add(t1);
add(t2);

//Add  button to frame 
Button b = new Button("Submit");
b.setBounds(30, 150, 100, 30);
add(b);

Button b1 = new Button("Clear");
b1.setBounds(140, 150, 100, 30);
add(b1);


//Attach window listener
addWindowListener(new WindowCloser());
}

//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}


Fifth Week Term Work Program 3

Question

















Program:

//Displays a frame containing a three CheckBox. Tick the
//CheckBox causes the background of the frame to change from
//white to define color.

import java.awt.*;
import java.awt.event.*;

import javafx.scene.control.CheckBox;

public class checkboxcolor {
public static void main(String[] args) {
Frame f = new ChangecheckboxColorFrame("Check Box");
f.setSize(220, 200);
f.setVisible(true);
}
}
//Frame class
class ChangecheckboxColorFrame extends Frame {
Checkbox checkBox1 = new Checkbox("Red",false);
Checkbox checkBox2 = new Checkbox("Green",false);    
Checkbox checkBox3 = new Checkbox("Blue",false);    
public ChangecheckboxColorFrame(String title) {
super(title);
setLayout(null);
setBackground(Color.white);

//Add  Checkbox to frame and attach listener
checkBox1.setBounds(10,150, 80,50);    
checkBox2.setBounds(90,150, 80,50);  
checkBox3.setBounds(170,150, 80,50);    
add(checkBox1);
checkBox1.addItemListener(new ColorItemListener());
add(checkBox2);    
checkBox2.addItemListener(new ColorItemListener());
add(checkBox3); 
checkBox3.addItemListener(new ColorItemListener());//Attach //window listener
addWindowListener(new WindowCloser());
}
//Listener for checkbox
class ColorItemListener implements ItemListener{
public void itemStateChanged(ItemEvent e) {

boolean a1=checkBox1.getState();
boolean a2=checkBox2.getState();
boolean a3=checkBox3.getState();
if(a1==true && a2==true && a3==true) {
setBackground(Color.WHITE);
}
else if(a1==true) {
if(a2==true) {
setBackground(Color.YELLOW);
}
else if(a3==true) {
setBackground(Color.MAGENTA);
}
else {
setBackground(Color.RED);
}
}
else if(a2==true) {
if(a3==true) {
setBackground(Color.CYAN);
}
else{
setBackground(Color.GREEN);
}
}
else if(a3==true) {
setBackground(Color.BLUE);
}
else {
setBackground(Color.BLACK);
}
}
}
//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}

Fifth Week Term Work Program 2

Question

Program:

//Displays a frame containing a three button. Pressing the
//button causes the background of the frame to change from
//white to define color.

import java.awt.*;
import java.awt.event.*;
import java.awt.Button;

public class threecolor {
public static void main(String[] args) {
Frame f = new ChangethreeColorFrame("Colors");
f.setSize(210, 200);
f.setVisible(true);
}
}
//Frame class
class ChangethreeColorFrame extends Frame {
public ChangethreeColorFrame(String title) {
super(title);
setLayout(null);
setBackground(Color.white);

//Add  button to frame and attach listener
Button b1 = new Button("Red");
b1.setBounds(20, 150, 50, 30);
add(b1);
b1.addActionListener(new ButtonListener());
Button b2 = new Button("Blue");
b2.setBounds(80, 150, 50, 30);
add(b2);
b2.addActionListener(new ButtonListener());
Button b3 = new Button("Green");
b3.setBounds(140, 150, 50, 30);
add(b3);
b3.addActionListener(new ButtonListener());

//Attach window listener
addWindowListener(new WindowCloser());
}

//Listener for button
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {

  if (evt.getActionCommand().equals("Red"))
    setBackground(Color.RED);
  else if (evt.getActionCommand().equals("Blue"))
    setBackground(Color.BLUE);
  else if (evt.getActionCommand().equals("Green"))
    setBackground(Color.GREEN);
else
  setBackground(Color.white);
}
}

//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}

Fifth Week Term Work Program 1

Question 




Program:
//Displays a frame containing a single button. Pressing the
//button causes the background of the frame to change Color Randomly 

import java.util.Random;

 import java.awt.*;

import java.awt.event.*;

//Driver class
public class ChangingColor {
public static void main(String[] args) {
Frame f = new ChangeColorFrame("Random Colors");
f.setSize(160, 100);
f.setVisible(true);
}
}
//Frame class
class ChangeColorFrame extends Frame {
public ChangeColorFrame(String title) {
// Set title, layout, and background color
super(title);
setLayout(null);
setBackground(Color.white);
// Add "Change color" button to frame and attach listener
Button b = new Button("Random");
b.setBounds(60, 60, 60, 30);;
add(b);
b.addActionListener(new ButtonListener());
// Attach window listener
addWindowListener(new WindowCloser());
}
//Listener for button
class ButtonListener implements ActionListener {
Random rand=new Random();
public void actionPerformed(ActionEvent evt) {
int i=rand.nextInt(256);
int j=rand.nextInt(256);
int k=rand.nextInt(256);
Color c = new Color(i, j, k);
setBackground(c);
}
}
//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}