Java中Applet小程序的编写
1个回答
展开全部
import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * @author Hardneedl */public class NumberApplet extends JApplet { private JTextField n1Field,n2Field; private JTextArea outArea; public NumberApplet() throws HeadlessException { Container container = getContentPane(); container.setLayout(new GridLayout(0,1,2,2)); container.add(n1Field = new JTextField(10)); container.add(n2Field = new JTextField(10)); container.add(new JButton(new ComputeAction())); container.add(new JScrollPane(outArea = new JTextArea(){ public boolean isEditable() {return false;} })); } private class ComputeAction extends AbstractAction { public ComputeAction() { super("Compute"); putValue(Action.MNEMONIC_KEY, Integer.valueOf('C')); } public void actionPerformed(ActionEvent e) { int d1,d2; try { d1 = Integer.parseInt( n1Field.getText() ); d2 = Integer.parseInt( n2Field.getText() ); outArea.setText(null); outArea.append("number square cube\n"); for (int i=Math.min(d1,d2),j=Math.max(d1,d2); i i++) { int t; outArea.append(i + " " + (t=i*i) + " " + (t*i)+'\n'); } } catch(NumberFormatException ne){} } }}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询