-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path52_Button
More file actions
65 lines (53 loc) · 1.82 KB
/
52_Button
File metadata and controls
65 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// JButton = a button that performs an action when clicked on
<Main.java>
public class Main {
public static void main(String[] args){
new myFrame();
}
}
<myFrame.java>
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class myFrame extends JFrame implements ActionListener{
JButton button;
JLabel label;
myFrame(){
ImageIcon icon = new ImageIcon("icebear.png");
ImageIcon icon2 = new ImageIcon("Ph.png");
label = new JLabel();
label.setIcon(icon2);
label.setBounds(150,250,150,150);
label.setVisible(false);
button = new JButton();
button.setBounds(200,100,250,100);
button.addActionListener(e->System.out.println("poo"));
button.setText("I'm a butt");
button.setFocusable(false);//to cancel out the textbox
button.setIcon(icon);
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.BOTTOM);
button.setFont(new Font("Comic Sans",Font.BOLD,25));
button.setIconTextGap(-15);
button.setForeground(Color.cyan);
button.setBackground(Color.lightGray);
button.setBorder(BorderFactory.createEtchedBorder());
/* button.setEnabled(false); //Disable a button */
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null); //no layout manager
this.setSize(500,500);
this.setVisible(true);
this.add(button);
this.add(label);
}
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
/*System.out.println("poo");
//button.setEnabled((false)); //Button can only be clicked once */
label.setVisible(true);
}
}
}
//QTA