import java.awt.*; import java.awt.event.*; public class TestJavaApplication extends Frame implements ActionListener{ Label l1; TextField t1; Button b1; public TestJavaApplication () { super(); setSize(300,100); setLayout(null); l1 = new Label("please type number:"); l1.setBounds(50,30,200,20); Font f1 = new Font("Dialog",Font.BOLD, 14); l1.setFont(f1); add(l1); t1 = new TextField("10"); t1.setBounds(50,60,200,20); add(t1); b1 = new Button("OK"); b1.setBounds(100,100,100,25); add(b1); b1.addActionListener(this); } public static void main(String args[]) { TestJavaApplication f = new TestJavaApplication(); f.show(); } public void actionPerformed(ActionEvent e) { String s = t1.getText(); int n = Integer.parseInt(s); int m = 0; for (int i = 1; i <= n; i++) m += i; s = Integer.toString(m); l1.setText("total: " + s); } }
ボタンイベント
トラックバック(0)
トラックバックURL: http://winnote.adg7.com/mt/mt-tb.cgi/248
コメントする