初学Java
开始学Java了,纪念一下我的第一篇Java代码
package com.runoob.text; //import java.io; import java.awt.*; import java.awt.event.*; public class hello { public static void main(String []args) { ApplicationFrame AF= new ApplicationFrame(); } } class ApplicationFrame extends Frame implements ActionListener { Label prompt; TextField text1,text2; Button btn; int a=0,b=0; ApplicationFrame() { super("计算器"); prompt= new Label("请输入两个数:"); text1= new TextField(4); text2= new TextField(4); btn =new Button("计算"); setLayout(new FlowLayout()); add(prompt); add(text1); add(text2); add(btn); btn.addActionListener(this); show(); } public void actionPerformed(ActionEvent e) { a=Integer.parseInt(text1.getText()); b=Integer.parseInt(text2.getText()); } public void paint(Graphics g) { g.drawString("运算结果:"+a+"*"+b+"="+a*b,20,80); } }
如果你够坚强够勇敢,你就能驾驭他们