java图形用户界面设计
设计要求:(1)给两个数x,y(随机给)(2)要求操作者口算出两数之和,将答案填入文本框txetxy中(3)程序能够判断操作者计算是否正确(若对,显示“对了”,若错,显示...
设计要求:
(1)给两个数x,y(随机给)
(2)要求操作者口算出两数之和,将答案填入文本框txet xy中
(3)程序能够判断操作者计算是否正确(若对,显示“对了”,若错,显示“请重做”)
哪位高手愿意帮忙小弟一下,感激不尽 展开
(1)给两个数x,y(随机给)
(2)要求操作者口算出两数之和,将答案填入文本框txet xy中
(3)程序能够判断操作者计算是否正确(若对,显示“对了”,若错,显示“请重做”)
哪位高手愿意帮忙小弟一下,感激不尽 展开
3个回答
展开全部
这么简单的问题最好是自己写又好处的。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
等着,我给你做!
我这个简单!!!
package untitled1;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Random;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame2 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
Random rand=new Random();
int randomNumber=rand.nextInt();
int randomSetup1=(Math.abs(randomNumber))%59;
int randomSetup2=(Math.abs(randomNumber))%20;
String a=Integer.toString(randomSetup1);
String b=Integer.toString(randomSetup2);
String c=Integer.toString(randomSetup1+randomSetup2);
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JOptionPane jOptionPane1 = new JOptionPane();
public Frame2() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jLabel1.setToolTipText("");
jLabel1.setBounds(new Rectangle(238, 51, 26, 34));
jLabel2.setToolTipText("");
jLabel2.setBounds(new Rectangle(234, 85, 21, 24));
jLabel3.setText("产生的随机数1:");
jLabel3.setBounds(new Rectangle(119, 61, 99, 15));
jLabel4.setText("产生的随机数2:");
jLabel4.setBounds(new Rectangle(119, 91, 90, 15));
jLabel5.setText("两数相加,请输入计算结果:");
jLabel5.setBounds(new Rectangle(71, 143, 157, 34));
jTextField1.setBounds(new Rectangle(234, 153, 116, 20));
jButton1.setBounds(new Rectangle(175, 229, 83, 25));
jButton1.setText("确定");
jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
jOptionPane1.setBounds(new Rectangle(400, 309, 262, 90));
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jLabel3);
contentPane.add(jLabel4);
contentPane.add(jButton1);
contentPane.add(jTextField1);
contentPane.add(jLabel5);
contentPane.add(jOptionPane1);
jLabel1.setText(a);
jLabel2.setText(b);
}
/**
* abs
*
* @param randomNumber int
* @return int
*/
private int abs(int randomNumber) {
return 0;
}
public void jButton1_actionPerformed(ActionEvent e) {
if(jTextField1.getText().equals(c))
jOptionPane1.showMessageDialog(this,"恭喜你,回答正确!","消息",JOptionPane.INFORMATION_MESSAGE);
else
jOptionPane1.showMessageDialog(this,"不好意思,回答错误!","消息",JOptionPane.ERROR_MESSAGE);
}
}
class Frame2_jButton1_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
我这个简单!!!
package untitled1;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Random;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame2 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
Random rand=new Random();
int randomNumber=rand.nextInt();
int randomSetup1=(Math.abs(randomNumber))%59;
int randomSetup2=(Math.abs(randomNumber))%20;
String a=Integer.toString(randomSetup1);
String b=Integer.toString(randomSetup2);
String c=Integer.toString(randomSetup1+randomSetup2);
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JOptionPane jOptionPane1 = new JOptionPane();
public Frame2() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jLabel1.setToolTipText("");
jLabel1.setBounds(new Rectangle(238, 51, 26, 34));
jLabel2.setToolTipText("");
jLabel2.setBounds(new Rectangle(234, 85, 21, 24));
jLabel3.setText("产生的随机数1:");
jLabel3.setBounds(new Rectangle(119, 61, 99, 15));
jLabel4.setText("产生的随机数2:");
jLabel4.setBounds(new Rectangle(119, 91, 90, 15));
jLabel5.setText("两数相加,请输入计算结果:");
jLabel5.setBounds(new Rectangle(71, 143, 157, 34));
jTextField1.setBounds(new Rectangle(234, 153, 116, 20));
jButton1.setBounds(new Rectangle(175, 229, 83, 25));
jButton1.setText("确定");
jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
jOptionPane1.setBounds(new Rectangle(400, 309, 262, 90));
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jLabel3);
contentPane.add(jLabel4);
contentPane.add(jButton1);
contentPane.add(jTextField1);
contentPane.add(jLabel5);
contentPane.add(jOptionPane1);
jLabel1.setText(a);
jLabel2.setText(b);
}
/**
* abs
*
* @param randomNumber int
* @return int
*/
private int abs(int randomNumber) {
return 0;
}
public void jButton1_actionPerformed(ActionEvent e) {
if(jTextField1.getText().equals(c))
jOptionPane1.showMessageDialog(this,"恭喜你,回答正确!","消息",JOptionPane.INFORMATION_MESSAGE);
else
jOptionPane1.showMessageDialog(this,"不好意思,回答错误!","消息",JOptionPane.ERROR_MESSAGE);
}
}
class Frame2_jButton1_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
class SumTest {
private int x;
private int y;
public SumTest() {
setXY();
}
private void setXY() {
this.x = (int) (Math.random() * 100);
this.y = (int) (Math.random() * 100);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String display() {
return "X :" + getX() + " Y :" + getY();
}
}
public class Panel extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelDisplay;
private JLabel labelSum;
private JLabel labelError;
private JTextField textFieldSum;
private JButton submitButton;
private JButton cancelButton;
private SumTest st;
private int x;
private int y;
private Panel(){
super("Add Check");
st = new SumTest();
x = st.getX();
y = st.getY();
}
private void PanelMethod(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
labelSum = new JLabel("SumResult:");
labelDisplay = new JLabel();
labelDisplay.setText(st.display() + " ");
textFieldSum = new JTextField(5);
submitButton = new JButton("Sumbit");
cancelButton = new JButton("Clear");
labelError = new JLabel();
class cleanB implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
textFieldSum.setText("");
}
}
class submitB implements ActionListener {
public void actionPerformed(ActionEvent arg0){
String sum = "";
int sumResult = 0;
sum = textFieldSum.getText();
try {
sumResult = Integer.parseInt(sum);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if(x+y == sumResult) {
labelError.setText("Right");
} else {
labelError.setText("Wrong!Input Again");
}
}
}
cancelButton.addActionListener(new cleanB());
submitButton.addActionListener(new submitB());
getContentPane().add(labelDisplay);
getContentPane().add(labelSum);
getContentPane().add(textFieldSum);
getContentPane().add(submitButton);
getContentPane().add(cancelButton);
getContentPane().add(labelError);
setSize(180, 160);
}
public static void main(String[] args){
final Panel frame = new Panel();
frame.PanelMethod();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(400, 400);
frame.setResizable(false);
frame.setVisible(true);
}
}
测试通过,有问题可以发消息给我
import java.awt.event.*;
import javax.swing.*;
class SumTest {
private int x;
private int y;
public SumTest() {
setXY();
}
private void setXY() {
this.x = (int) (Math.random() * 100);
this.y = (int) (Math.random() * 100);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String display() {
return "X :" + getX() + " Y :" + getY();
}
}
public class Panel extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelDisplay;
private JLabel labelSum;
private JLabel labelError;
private JTextField textFieldSum;
private JButton submitButton;
private JButton cancelButton;
private SumTest st;
private int x;
private int y;
private Panel(){
super("Add Check");
st = new SumTest();
x = st.getX();
y = st.getY();
}
private void PanelMethod(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
labelSum = new JLabel("SumResult:");
labelDisplay = new JLabel();
labelDisplay.setText(st.display() + " ");
textFieldSum = new JTextField(5);
submitButton = new JButton("Sumbit");
cancelButton = new JButton("Clear");
labelError = new JLabel();
class cleanB implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
textFieldSum.setText("");
}
}
class submitB implements ActionListener {
public void actionPerformed(ActionEvent arg0){
String sum = "";
int sumResult = 0;
sum = textFieldSum.getText();
try {
sumResult = Integer.parseInt(sum);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if(x+y == sumResult) {
labelError.setText("Right");
} else {
labelError.setText("Wrong!Input Again");
}
}
}
cancelButton.addActionListener(new cleanB());
submitButton.addActionListener(new submitB());
getContentPane().add(labelDisplay);
getContentPane().add(labelSum);
getContentPane().add(textFieldSum);
getContentPane().add(submitButton);
getContentPane().add(cancelButton);
getContentPane().add(labelError);
setSize(180, 160);
}
public static void main(String[] args){
final Panel frame = new Panel();
frame.PanelMethod();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(400, 400);
frame.setResizable(false);
frame.setVisible(true);
}
}
测试通过,有问题可以发消息给我
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |