跪求,加急,做一个JAVA课程设计!不难……

发布网友 发布时间:2022-04-23 21:00

我来回答

4个回答

热心网友 时间:2023-10-09 14:11

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Show extends JFrame{
JTextArea taIn = new JTextArea();
JTextArea taOut = new JTextArea();
JButton jbAdd = new JButton("添加");
JButton jbDel = new JButton("删除");
JButton jbEsc = new JButton("退出");
public Show(){
JScrollPane jsIn = new JScrollPane(taIn);
JScrollPane jsOut = new JScrollPane(taOut);
setSize(300,400);
Container c = getContentPane();
JPanel pup = new JPanel(new GridLayout(2,1));
pup.add(jsIn);
pup.add(jsOut);
JPanel pdown = new JPanel();
pdown.add(jbAdd);
pdown.add(jbDel);
pdown.add(jbEsc);
c.add(pup,BorderLayout.CENTER);
c.add(pdown,BorderLayout.SOUTH);
taOut .setEditable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jbEsc.addActionListener(new Exit());
jbAdd.addActionListener(new Add());
jbDel.addActionListener(new Delete());
}
private class Add implements ActionListener{
public void actionPerformed(ActionEvent e){
String strIn = taIn.getText();
if(strIn.equals("")){
JOptionPane.showMessageDialog(null,"您还没有输入!");
}else{
String strOld = taOut.getText();
taIn.setText("");
if(strOld==null){
strOld = "";
}
String myPrint = strIn + "\n"+"\n" +strOld;
taOut.setText(myPrint);
}

}
}
private class Delete implements ActionListener{
public void actionPerformed(ActionEvent e){
int opt = JOptionPane.showConfirmDialog(null, "确定删除显示内容吗?", "对话框", JOptionPane.YES_NO_OPTION);
if(opt == JOptionPane.YES_OPTION){
taOut.setText("");
}

}
}
private class Exit implements ActionListener{
public void actionPerformed(ActionEvent e){
dispose();
}
}
public void setSize(int width, int height) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((d.width - width) / 2, (d.height - height) / 2, width, height);
}
public static void main(String[] args) {
new Show();

}

}

热心网友 时间:2023-10-09 14:11

我感觉用C#做比较好 添加删除 就在里面写就好了

热心网友 时间:2023-10-09 14:11

楼主,对不起,你的问题我只能拿两分了!

热心网友 时间:2023-10-09 14:12

“添加,删除” 按钮是干什么用的?

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com