`
owlman
  • 浏览: 63345 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

复习下java applet……

阅读更多

今天复习了下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());
}
}
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics