-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.JButton.java
More file actions
58 lines (51 loc) · 1.71 KB
/
4.JButton.java
File metadata and controls
58 lines (51 loc) · 1.71 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
//Main Class
public class Main{
public static void main(String[] args){
new MyFrame();
}
}
//MyFrame Class
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyFrame extends JFrame /*implements ActionListener*/{
JButton btn;
MyFrame(){
//Button Elements..
btn = new JButton();
btn.setBounds(75,100,250,150);
btn.setText("Click Me");
btn.setFocusable(false);
btn.setFont(new Font("MV Boli", Font.BOLD, 17));
btn.setForeground(Color.red);
btn.setBackground(Color.green);
btn.setBorder(BorderFactory.createEtchedBorder());
ImageIcon btn_img = new ImageIcon("btn.png");
btn.setIcon(btn_img);
btn.setHorizontalTextPosition(JButton.CENTER);
btn.setVerticalTextPosition(JButton.BOTTOM);
btn.setIconTextGap(50);
btn.setHorizontalAlignment(JButton.LEFT);
btn.setVerticalAlignment(JButton.BOTTOM);
//btn.setEnabled(false);
//btn.addActionListener(this);
btn.addActionListener(e -> System.out.println("Assalamu Alaikum!"));
//Frame Elements..
this.setVisible(true);
this.setLayout(null);
this.setSize(400,400);
this.setTitle("....This is JFrame Title....");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon frm_img = new ImageIcon("file_name");
this.setIconImage(frm_img.getImage());
this.add(btn);
}
// @Override
// public void actionPerformed(ActionEvent e){
// if(e.getSource()==btn){
// System.out.println("Assalamu Alaikum!");
// btn.setEnabled(false);
// }
// }
}