1 import javax.swing.*;
2 import java.awt.Font;
3 import java.awt.BorderLayout;
4
5 public class DisplayMessageApp extends JApplet {
6 private String message = "A default message";
7 private int x = 20;
8 private int y = 20;
9
10
11 private boolean isStandalone = false;
12
13
14 public void init() {
15 if (!isStandalone) {
16
17 message = getParameter("MESSAGE");
18 x = Integer.parseInt(getParameter("X"));
19 y = Integer.parseInt(getParameter("Y"));
20 }
21
22
23 MessagePanel messagePanel = new MessagePanel(message);
24 messagePanel.setFont(new Font("SansSerif", Font.BOLD, 20));
25 messagePanel.setXCoordinate(x);
26 messagePanel.setYCoordinate(y);
27
28
29 add(messagePanel);
30 }
31
32
37 public static void main(String[] args) {
38
39 JFrame frame = new JFrame("DisplayMessageApp");
40
41
42 DisplayMessageApp applet = new DisplayMessageApp();
43
44
45 applet.isStandalone = true;
46
47
48 applet.getCommandLineParameters(args);
49
50
51 frame.add(applet, BorderLayout.CENTER);
52
53
54 applet.init();
55 applet.start();
56
57
58 frame.setSize(300, 300);
59 frame.setLocationRelativeTo(null);
60 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61 frame.setVisible(true);
62 }
63
64
65 private void getCommandLineParameters(String[] args) {
66
67 if (args.length != 3) {
68 System.out.println(
69 "Usage: java DisplayMessageApp x y message");
70 System.exit(1);
71 }
72 else {
73 x = Integer.parseInt(args[0]);
74 y = Integer.parseInt(args[1]);
75 message = args[2];
76 }
77 }
78 }