JAVA 如何实现 点击一个按钮,删除按钮功能
主要程序读取数据——生成按钮——选择按钮(可多选)——用一个删除按钮错删除所选按钮按钮——再次存入数据...
主要程序 读取数据——生成按钮——选择按钮(可多选)——用一个删除按钮错删除所选按钮按钮——再次存入数据
展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
展开全部
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TwoButtonExample extends WindowAdapter implements MouseListener {
private Frame f;
private Panel a, b;
private CardLayout cardLayout;
public static void main(String[] args) {
new TwoButtonExample();
}
public TwoButtonExample(){
f = new Frame("Test");
a = new Panel();
b = new Panel();
Button b1 = new Button("下面的数字123");
Button b2 = new Button("上面的");
b1.addMouseListener(this);
b2.addMouseListener(this);
a.add(b1);
b.add(b2);
cardLayout = new CardLayout();
f.setLayout(cardLayout);
f.add(a, "First");
f.add(b, "Second");
cardLayout.show(f, "Second");
f.pack();
f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void mouseClicked(MouseEvent e) {
cardLayout.first(f);
b.setVisible(false);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
不懂可追问
import java.awt.CardLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TwoButtonExample extends WindowAdapter implements MouseListener {
private Frame f;
private Panel a, b;
private CardLayout cardLayout;
public static void main(String[] args) {
new TwoButtonExample();
}
public TwoButtonExample(){
f = new Frame("Test");
a = new Panel();
b = new Panel();
Button b1 = new Button("下面的数字123");
Button b2 = new Button("上面的");
b1.addMouseListener(this);
b2.addMouseListener(this);
a.add(b1);
b.add(b2);
cardLayout = new CardLayout();
f.setLayout(cardLayout);
f.add(a, "First");
f.add(b, "Second");
cardLayout.show(f, "Second");
f.pack();
f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void mouseClicked(MouseEvent e) {
cardLayout.first(f);
b.setVisible(false);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
不懂可追问
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询