Created
October 29, 2010 21:08
-
-
Save njbartlett/654413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example.gui; | |
import java.awt.Container; | |
import java.awt.Dimension; | |
import java.awt.event.*; | |
import javax.swing.*; | |
import org.example.api.Greeting; | |
import aQute.bnd.annotation.component.*; | |
@Component | |
public class GreetUI extends JFrame { | |
private Greeting greeting; | |
public GreetUI() { | |
Container content = getContentPane(); | |
content.setLayout(new BoxLayout(content, BoxLayout.LINE_AXIS)); | |
content.add(new JLabel("Name:")); | |
final JTextField text = new JTextField(); | |
text.setPreferredSize(new Dimension(100, 0)); | |
content.add(text); | |
final JButton button = new JButton("Greet"); | |
content.add(button); | |
button.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
String response = (greeting != null) | |
? greeting.sayHello(text.getText()) | |
: "Greeting service unavailable"; | |
JOptionPane.showMessageDialog(button, response); | |
} | |
}); | |
} | |
@Reference | |
public void setGreeting(Greeting greeting) { | |
this.greeting = greeting; | |
} | |
@Activate | |
public void start() { | |
pack(); | |
setVisible(true); | |
} | |
@Deactivate | |
public void stop() { | |
setVisible(false); | |
} | |
public static void main(String[] args) { | |
new GreetUI().start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment