GUI(一) 一些自已看的东西
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Jf
{
??? private JFrame f=new JFrame("一個(gè)小程序");
??? private JLabel l1=new JLabel("+");
??? private JLabel l2=new JLabel("=");
??? private JTextField t1=new JTextField("0.0");
??? private JTextField t2=new JTextField("0.0");
??? private JButton b=new JButton("Add");
?????
?public Jf()
?{ f.getContentPane().setLayout(new FlowLayout());
????? f.getContentPane().add(t1);
????? f.getContentPane().add(l1);
????? f.getContentPane().add(t2);
????? f.getContentPane().add(l2);
????? f.getContentPane().add(b);
????? f.setSize(200,100);
????? f.setVisible(true);
?????
????? b.addActionListener(new ActionListener(){
????? ??
????? ? public void actionPerformed(ActionEvent e)
????? ? {
????? ??
????? ?? float a1=Float.parseFloat(t1.getText());
????? ?? float a2=Float.parseFloat(t2.getText());
????? ?? float a3=a1+a2;
????? ?? l2.setText("="+a3);
????? ? }
????? ?});
????? f.addWindowListener(new WindowAdapter(){
????? ?? public void windowClosing(WindowEvent e)
????? ?? { System.exit(0);
????? ?? }
????? ?});?
?}?
?public static void main(String[] args) {
???? new Jf();
???? }
}????
????
總結(jié)
以上是生活随笔為你收集整理的GUI(一) 一些自已看的东西的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java程序优化
- 下一篇: java中文乱码的解决