Skip to content

Instantly share code, notes, and snippets.

@njbartlett
Created October 29, 2010 21:08
Show Gist options
  • Save njbartlett/654413 to your computer and use it in GitHub Desktop.
Save njbartlett/654413 to your computer and use it in GitHub Desktop.
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