编写一个Java程序,在程序中建立一个窗口,在文本框中显示鼠标的信息。要求运行结果如图1所示。 10
1个回答
2015-05-31 · 知道合伙人互联网行家
关注
展开全部
package test;
import java.awt.FlowLayout;
import java.awt肌常冠端攉得圭全氦户.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Test {
public static void main(String[] args) {
new Test();
}
private Test() {
final JFrame jf = new JFrame("求和复制");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(400, 150);
jf.setLayout(new FlowLayout());
final JTextField jtf1 = new JTextField(8);
jf.add(jtf1);
final JTextField jtf2 = new JTextField(8);
jf.add(jtf2);
final JTextField jtf3 = new JTextField(8);
jf.add(jtf3);
final JTextField jtf4 = new JTextField(8);
jf.add(jtf4);
JButton btn1 = new JButton("求和");
jf.add(btn1);
JButton btn2 = new JButton("复制");
jf.add(btn2);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ("".equals(jtf1.getText().trim()) || "".equals(jtf1.getText().trim())) {
JOptionPane.showMessageDialog(jf, "请在输入框中输入数字");
} else {
try {
jtf3.setText("" + (new BigDecimal(jtf1.getText().trim())).add(new BigDecimal(jtf2.getText().trim())) );
} catch (Exception e1) {
JOptionPane.showMessageDialog(jf, "请在输入框中输入数字");
}
}
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerform ed(ActionEvent e) {
jtf4.setText(jtf3.getText());
}
});
jf.setVisible(true);
}
}
import java.awt.FlowLayout;
import java.awt肌常冠端攉得圭全氦户.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Test {
public static void main(String[] args) {
new Test();
}
private Test() {
final JFrame jf = new JFrame("求和复制");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(400, 150);
jf.setLayout(new FlowLayout());
final JTextField jtf1 = new JTextField(8);
jf.add(jtf1);
final JTextField jtf2 = new JTextField(8);
jf.add(jtf2);
final JTextField jtf3 = new JTextField(8);
jf.add(jtf3);
final JTextField jtf4 = new JTextField(8);
jf.add(jtf4);
JButton btn1 = new JButton("求和");
jf.add(btn1);
JButton btn2 = new JButton("复制");
jf.add(btn2);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ("".equals(jtf1.getText().trim()) || "".equals(jtf1.getText().trim())) {
JOptionPane.showMessageDialog(jf, "请在输入框中输入数字");
} else {
try {
jtf3.setText("" + (new BigDecimal(jtf1.getText().trim())).add(new BigDecimal(jtf2.getText().trim())) );
} catch (Exception e1) {
JOptionPane.showMessageDialog(jf, "请在输入框中输入数字");
}
}
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerform ed(ActionEvent e) {
jtf4.setText(jtf3.getText());
}
});
jf.setVisible(true);
}
}
追问
import java.awt肌常冠端攉得圭全氦户什么鬼
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询