077file Oop
077file Oop
/**
*
* @author Student
*/
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
}
}
Output:
Activity 2:
package com.mycompany.testing1;
/**
*
* @author Student
*/
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public Testing1(){
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,20));
tf1=new JTextField(8);
this.add(tf1);
label=new JLabel("New Text");
this.add(label);
b=new JButton("Change");
b.addActionListener(new myHandler());
add(b);
}
}
Output:
Activity 3:
package com.mycompany.testing1;
/**
*
* @author Student
*/
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public Testing1(){
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,20));
tf1=new JTextField(8);
this.add(tf1);
label=new JLabel("New Text");
this.add(label);
b=new JButton("Change");
b.addActionListener(new myHandler());
add(b);
b1=new JButton("Disappear");
b1.addActionListener(new myHandler());
add(b1);
}
}
Output:
Home Activities 1:
package com.mycompany.displaytextbook;
/**
*
* @author Student
*/
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String enteredText = textField.getText();
label.setText("You entered: " + enteredText);
}
});
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
/**
*
* @author Student
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public RadioButtonTest() {
super("RadioButton Test");
setLayout(new FlowLayout());
textField = new JTextField("Watch the font style change", 20);
textField.setFont(new Font("Serif", Font.PLAIN, 14));
add(textField);
plainButton = new JRadioButton("Plain", true);
boldButton = new JRadioButton("Bold", false);
italicButton = new JRadioButton("Italic", false);
boldItalicButton = new JRadioButton("BoldItalic", false);
group = new ButtonGroup();
group.add(plainButton);
group.add(boldButton);
group.add(italicButton);
group.add(boldItalicButton);
add(plainButton);
add(boldButton);
add(italicButton);
add(boldItalicButton);
RadioButtonHandler handler = new RadioButtonHandler();
plainButton.addActionListener(handler);
boldButton.addActionListener(handler);
italicButton.addActionListener(handler);
boldItalicButton.addActionListener(handler);
}
private class RadioButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (plainButton.isSelected()) {
textField.setFont(new Font("Serif", Font.PLAIN, 14));
} else if (boldButton.isSelected()) {
textField.setFont(new Font("Serif", Font.BOLD, 14));
} else if (italicButton.isSelected()) {
textField.setFont(new Font("Serif", Font.ITALIC, 14));
} else if (boldItalicButton.isSelected()) {
textField.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 14));
}
}
}
public static void main(String[] args) {
RadioButtonTest frame = new RadioButtonTest();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Output: