Skip to content

Commit d47e766

Browse files
committed
CheckBox programs 65
1 parent ee682a7 commit d47e766

File tree

8 files changed

+112
-0
lines changed

8 files changed

+112
-0
lines changed

src/CheckBox62/Gui.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package CheckBox62;
2+
import java.awt.FlowLayout;
3+
import java.awt.event.ActionListener;
4+
import java.awt.event.ActionEvent;
5+
import javax.swing.JFrame;
6+
import javax.swing.JButton;
7+
import javax.swing.Icon;
8+
import javax.swing.ImageIcon;
9+
import javax.swing.JOptionPane;
10+
public class Gui extends JFrame{ //inherits everything from JFrame
11+
private JButton reg;
12+
private JButton custom;
13+
14+
//constructor
15+
public Gui(){
16+
super("The title");
17+
setLayout(new FlowLayout()); // default Layout
18+
reg = new JButton("reg Button");
19+
add(reg);
20+
Icon b = new ImageIcon(getClass().getResource("b.png"));
21+
Icon x = new ImageIcon(getClass().getResource("x.png"));
22+
custom = new JButton("Custom", b);
23+
custom.setRolloverIcon(x);
24+
add(custom);
25+
26+
HandlerClass handler = new HandlerClass();
27+
reg.addActionListener(handler);
28+
custom.addActionListener(handler);
29+
}
30+
private class HandlerClass implements ActionListener{
31+
//implements means uses methods but has to overwrite them!
32+
public void actionPerformed(ActionEvent event){
33+
JOptionPane.showMessageDialog(null,String.format("%s",event.getActionCommand()));
34+
}
35+
}
36+
37+
}

src/CheckBox62/b.png

1.7 KB
Loading

src/CheckBox62/checkBox.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package CheckBox62;
2+
import java.awt.FlowLayout;
3+
import java.awt.event.ActionListener;
4+
import java.awt.event.ActionEvent;
5+
import javax.swing.JFrame;
6+
import javax.swing.JButton;
7+
import javax.swing.Icon;
8+
import javax.swing.ImageIcon;
9+
import javax.swing.JOptionPane;
10+
11+
class checkBox {
12+
public static void main(String[] args){
13+
Gui go = new Gui();
14+
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15+
go.setSize(300,250);
16+
go.setVisible(true);
17+
}
18+
19+
}

src/CheckBox62/x.png

2.82 KB
Loading

src/CheckBox64/Gui.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package CheckBox64;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.*;
6+
import java.util.logging.Handler;
7+
8+
public class Gui extends JFrame { //inherits everything from JFrame
9+
private JTextField tf;
10+
private JCheckBox boldbox;
11+
private JCheckBox italicbox;
12+
13+
public Gui() {
14+
super("the title");
15+
setLayout(new FlowLayout());
16+
tf = new JTextField("This is a sentence", 20);
17+
tf.setFont(new Font("Serif", Font.PLAIN, 14));
18+
add(tf);
19+
boldbox = new JCheckBox("bold");
20+
21+
italicbox = new JCheckBox("italic");
22+
add(boldbox);
23+
add(italicbox);
24+
HandlerClass handler = new HandlerClass();
25+
boldbox.addItemListener(handler);
26+
italicbox.addItemListener(handler);
27+
}
28+
29+
private class HandlerClass implements ItemListener { //when implement should overwrite all methods !
30+
public void itemStateChanged(ItemEvent event) {
31+
Font font = null;
32+
if (boldbox.isSelected() && italicbox.isSelected())
33+
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
34+
else if (boldbox.isSelected())
35+
font = new Font("Serif", Font.BOLD, 14);
36+
else if (italicbox.isSelected())
37+
font = new Font("Serif", Font.ITALIC, 14);
38+
else
39+
font = new Font("Serif", Font.PLAIN, 14);
40+
tf.setFont(font);
41+
}
42+
}
43+
}

src/CheckBox64/b.png

1.7 KB
Loading

src/CheckBox64/checkBox.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package CheckBox64;
2+
3+
import javax.swing.*;
4+
5+
class checkBox {
6+
public static void main(String[] args){
7+
Gui go = new Gui();
8+
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9+
go.setSize(250,100);
10+
go.setVisible(true);
11+
}
12+
13+
}

src/CheckBox64/x.png

2.82 KB
Loading

0 commit comments

Comments
 (0)