Weitere ähnliche Inhalte
Mehr von Kiyotaka Oku (18)
Devsumi Openjam
- 2. Griffon
Groovy
Swing
DI MVC CoC
Java
2011 2 26
- 3. Swing(Java)
package sample; contentPane.add(button);
import java.awt.Container; setDefaultCloseOperation(EXIT_ON_CLOSE);
import java.awt.GridLayout; pack();
import java.awt.event.ActionEvent; setVisible(true);
import java.awt.event.ActionListener; }
import javax.swing.JButton; public static void main(String[] args) {
import javax.swing.JFrame; SwingUtilities.invokeLater(new Runnable() {
import javax.swing.JLabel; public void run() {
import javax.swing.JTextArea; new Hello();
import javax.swing.SwingUtilities; }
});
public class Hello extends JFrame { }
}
public Hello() {
super("Hello");
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(3, 1));
JLabel label = new JLabel("Label");
contentPane.add(label);
JTextArea textArea = new JTextArea("Text Area");
textArea.setColumns(20);
textArea.setRows(2);
contentPane.add(textArea);
JButton button = new JButton("Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
}
});
2011 2 26
- 4. Groovy
import groovy.swing.SwingBuilder
new SwingBuilder().edt {
frame(title:'Hello', show:true, pack:true) {
gridLayout(cols:1, rows:3)
label 'Label'
textArea('Text Area', rows:2, columns:20)
button('Button', actionPerformed:{ evt ->
...
})
}
}
2011 2 26
- 5. import groovy.swing.SwingBuilder
new SwingBuilder().edt {
frame(title:'Login', show:true, pack:true) {
tableLayout {
tr {
td {
label 'User Name'
}
td {
textField(columns:20)
}
}
tr {
td {
label 'Password'
}
td {
passwordField(columns:20)
}
}
tr {
td(colspan:2, align:'right') {
button 'Submit'
}
}
}
}
}
2011 2 26
- 10. Groovy
import groovy.swing.SwingBuilder
new SwingBuilder().edt {
frame(title:'Hello', show:true, pack:true) {
gridLayout(cols:1, rows:3)
label 'Label'
textArea('Text Area', rows:2, columns:20)
button('Button', actionPerformed:{ evt ->
...
})
}
}
2011 2 26
- 13. Getting Started
$ griffon create-app myapp
$ cd myapp
$ griffon run-app
2011 2 26
- 16. // Model
import groovy.beans.Bindable
class SampleModel {
@Bindable String text
}
// View
application(...) {
textField(text:bind(source:model, ’text’))
}
Model View
2011 2 26
- 17. // Model
import groovy.beans.Bindable
class SampleModel {
@Bindable String text
}
// View
application(...) {
textField(text:bind(target:model, ’text’))
}
View Model
2011 2 26
- 19. Java
public void actionPerformed(ActionEvent evt) {
new Thread() {
public void run() {
heavyTask();
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
textArea.append("Complete!n");
}
});
} catch (InterruptedException e) {
...
} catch (InvocationTargetException e) {
...
}
}
}.start();
}
2011 2 26
- 20. Groovy
// Controller
def heavyAction = { evt ->
doOutside {
heavyTask()
edt {
textArea.append 'Complete!n'
}
}
}
2011 2 26