//calling class
import javax.swing.JFrame;
class jcheckkbox {
public static void main(String args[]) {
jRadio roof = new jRadio();
roof.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
roof.setSize(300, 200);
roof.setVisible(true);
//secondary class
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class jcheckbox extends JFrame {
private JCheckBox cd;
private JCheckBox md;
private JTextField vcd;
public jcheckbox() {
super("Beer bar");
setLayout(new FlowLayout());
vcd = new JTextField("this is a code", 20);
vcd.setFont(new Font("Serif", Font.PLAIN, 22));
vcd.setToolTipText("yahoo");
add(vcd);
cd = new JCheckBox("bold");
md = new JCheckBox("italic");
add(md);
add(cd);
handler dahandler = new handler();
cd.addItemListener(dahandler);
md.addItemListener(dahandler);
}
private class handler implements ItemListener {
public void itemStateChanged(ItemEvent event) {
Font cool = null;
if (md.isSelected() && cd.isSelected())
cool = new Font("Serif", Font.BOLD + Font.ITALIC, 25);
else if (md.isSelected())
cool = new Font("Serif", Font.BOLD, 30);
else if (md.isSelected())
cool = new Font("Sans_Serif", Font.ITALIC, 30);
vcd.setFont(cool);
}}}
how to write a program in just one class i mean no need calling class for setsize or defaultcloseoperation etc because two classes are harder to compile when making a .jar or .exe out of it,i know there is another way but i want to use this method as it is a lot more easier to make buttons,textfields comboboxes with this method