forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLabel.java
More file actions
executable file
·39 lines (31 loc) · 1.09 KB
/
MyLabel.java
File metadata and controls
executable file
·39 lines (31 loc) · 1.09 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
import java.awt.*;
class HomeFrame extends Frame{
HomeFrame(String title) {
setTitle(title);
setSize(420, 420);
}
}
public class MyLabel {
public static void main(String[] args) {
Frame frame = new HomeFrame("MyLabel.java");
Image icon = Toolkit.getDefaultToolkit().getImage("../icon.png");
frame.setIconImage(icon);
Panel panel = new Panel();
frame.add(panel);
Label label1 = new Label(); // Constructor 1
label1.setText("Label 1"); // Method 1
// label1.setAlignment(Label.LEFT); // Method 2
panel.add(label1);
Label label2 = new Label("Label 2"); // Constructor 2
label2.setAlignment(Label.CENTER); // Method 2
panel.add(label2);
Label label3 = new Label("Label 3", Label.RIGHT); // Constructor 3
panel.add(label3);
frame.setVisible(true);
System.out.println("Text\t\tAlignment");
System.out.println(label1.getText() + "\t\t" + label1.getAlignment()); // Method 3 and 4
System.out.println(label2.getText() + "\t\t" + label2.getAlignment()); // Method 3 and 4
System.out.println(label3.getText() + "\t\t" + label3.getAlignment()); // Method 3 and 4
}
}
// No Events