ITeye博客

复习下java applet……

owlman · 2007-06-18 08:08 · Markdown

今天复习了下java,别说java写UI的功能就是强,完成下面这个界面代码不到50行:

ui.JPG

package MyApplet;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

 

public class GridLayoutDemo extends JApplet

{
private static final long serialVersionUID = 1L;
private JTextField t = null;
private Container cp = null;
private JButton bt = null;

@Override
public void init()
{
cp = getContentPane();
Container cp1 = new Container();
cp1.setLayout(new GridLayout(4,3));
t = new JTextField(12);
t.setHorizontalAlignment(JTextField.RIGHT);
cp.add(BorderLayout.NORTH, t);

for(int i = 1; i < 10; ++i)
{
bt = new JButton(""+i);
bt.addActionListener(new Bul());
cp1.add(bt);
}
bt = new JButton("*");
bt.addActionListener(new Bul());
cp1.add(bt);
bt = new JButton("0");
bt.addActionListener(new Bul());
cp1.add(bt);
bt = new JButton(".");
bt.addActionListener(new Bul());
cp1.add(bt);
cp.add(BorderLayout.CENTER,cp1);
super.init();
}

private class Bul implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
t.setText(((JButton)e.getSource()).getText());
}
}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。