COM6516-Week09

CornerString.java
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
66
67
68
69
70
71
/*
* Developed by Neo on 19/11/18 11:54.
* Last modified 19/11/18 11:54.
* Copyright (c) 2018. All rights reserved.
*/

import javax.swing.*;
import java.awt.*;

public class CornerString extends JFrame {
public CornerString() {
super("Corner String");

//For better looks.
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}

this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setSize(960, 480);
this.setResizable(false);
this.setLocationRelativeTo(null);

this.setContentPane(new StringPanel());

this.setVisible(true);
}

public static void main(String[] args) {
new CornerString();
}

public class StringPanel extends JPanel {
public StringPanel() {
super(new BorderLayout());

JLabel label1 = new JLabel("To be or not to be");
JLabel label2 = new JLabel("To be or not to be");
JLabel label3 = new JLabel("To be or not to be");
JLabel label4 = new JLabel("To be or not to be");

label1.setFont(new Font("Consolas", Font.PLAIN, 32));
label1.setForeground(Color.BLUE);
label2.setFont(new Font("Comic Sans MS", Font.PLAIN, 32));
label2.setForeground(Color.GREEN);
label3.setFont(new Font("Monospaced", Font.PLAIN, 32));
label3.setForeground(Color.RED);
label4.setFont(new Font("Courier", Font.PLAIN, 32));
label4.setForeground(Color.YELLOW);

JPanel northPanel = new JPanel();
northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));

northPanel.add(label1);
northPanel.add(Box.createHorizontalGlue());
northPanel.add(label2);

JPanel southPanel = new JPanel();
southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.X_AXIS));

southPanel.add(label3);
southPanel.add(Box.createHorizontalGlue());
southPanel.add(label4);

add(northPanel, BorderLayout.NORTH);
add(southPanel, BorderLayout.SOUTH);
}
}
}
GIFFrame.java
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
/*
* Developed by Neo on 19/11/18 15:44.
* Last modified 19/11/18 15:44.
* Copyright (c) 2018. All rights reserved.
*/

import javax.swing.*;

public class GIFFrame extends JFrame {
public GIFFrame() {
super("GIF Frame");

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

ImageIcon imageIcon = new ImageIcon("globe.gif", "globe");

setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());

JLabel imageLabel = new JLabel(imageIcon);

add(imageLabel);

setLocationRelativeTo(null);

setVisible(true);
}

public static void main(String[] args) {
new GIFFrame();
}
}
0%