teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2015/09/03 11:06

投稿

argius
argius

スコア9396

answer CHANGED
@@ -44,4 +44,58 @@
44
44
  }
45
45
 
46
46
  }
47
- ```
47
+ ```
48
+ ---
49
+
50
+ (追記)
51
+
52
+ どのようなプログラムをつなぐかによって書き方は変わってきますが、一例を示します。
53
+
54
+ ```lang-java
55
+ public final class App extends JFrame {
56
+
57
+ Hello hello;
58
+
59
+ public App() {
60
+ setTitle("App");
61
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
62
+ JButton button = new JButton("stop");
63
+ button.addActionListener(new ActionListener() {
64
+ @Override
65
+ public void actionPerformed(ActionEvent e) {
66
+ hello.sayHello();
67
+ }
68
+ });
69
+ JPanel p = new JPanel();
70
+ p.add(button);
71
+ add(p);
72
+ this.hello = new Hello("your name");
73
+ }
74
+
75
+ public static void main(String[] args) {
76
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
77
+ public void run() {
78
+ App app = new App();
79
+ app.setSize(300, 100);
80
+ app.setLocationRelativeTo(null);
81
+ app.setVisible(true);
82
+ }
83
+ });
84
+ }
85
+
86
+ }
87
+
88
+ final class Hello {
89
+
90
+ private final String name;
91
+
92
+ Hello(String name) {
93
+ this.name = name;
94
+ }
95
+
96
+ void sayHello() {
97
+ System.out.println("Hello, " + name);
98
+ }
99
+
100
+ }
101
+ ```