初学java一个弱智问题:如何隐藏JButton
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import MyWindowListener;
public class HideButton extends JFrame
{
public JButton east,west,south,north,centre;
public Container c;
public HideButton()
{
JButton east = new JButton("隐藏东方");
JButton west = new JButton("隐藏西方");
JButton south = new JButton("隐藏南方");
JButton north = new JButton("隐藏北方");
JButton centre = new JButton("隐藏中央");
c = getContentPane();
c.setLayout(new BorderLayout());
c.add(east,BorderLayout.EAST);
c.add(south,BorderLayout.SOUTH);
c.add(west,BorderLayout.WEST);
c.add(north,BorderLayout.NORTH);
c.add(centre,BorderLayout.CENTER);
east.addActionListener(new ButtonListener());
south.addActionListener(new ButtonListener());
west.addActionListener(new ButtonListener());
north.addActionListener(new ButtonListener());
centre.addActionListener(new ButtonListener());
setSize(300,200);
show();
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if(command.equals("隐藏东方"))
east.setVisible(false);
if(command.equals("隐藏南方"));
south.setVisible(false);
if(command.equals("隐藏西方"));
west.setVisible(false);
if(command.equals("隐藏北方"));
north.setVisible(false);
if(command.equals("隐藏中央"));
centre.setVisible(false);
}
}
public static void main(String[] args)
{
HideButton app = new HideButton();
app.addWindowListener(new MyWindowListener());
}
}
//编译可以通过,但是运行时不正常,估计是setVisible的问题
import java.awt.event.*;
import javax.swing.*;
import MyWindowListener;
public class HideButton extends JFrame
{
public JButton east,west,south,north,centre;
public Container c;
public HideButton()
{
JButton east = new JButton("隐藏东方");
JButton west = new JButton("隐藏西方");
JButton south = new JButton("隐藏南方");
JButton north = new JButton("隐藏北方");
JButton centre = new JButton("隐藏中央");
c = getContentPane();
c.setLayout(new BorderLayout());
c.add(east,BorderLayout.EAST);
c.add(south,BorderLayout.SOUTH);
c.add(west,BorderLayout.WEST);
c.add(north,BorderLayout.NORTH);
c.add(centre,BorderLayout.CENTER);
east.addActionListener(new ButtonListener());
south.addActionListener(new ButtonListener());
west.addActionListener(new ButtonListener());
north.addActionListener(new ButtonListener());
centre.addActionListener(new ButtonListener());
setSize(300,200);
show();
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if(command.equals("隐藏东方"))
east.setVisible(false);
if(command.equals("隐藏南方"));
south.setVisible(false);
if(command.equals("隐藏西方"));
west.setVisible(false);
if(command.equals("隐藏北方"));
north.setVisible(false);
if(command.equals("隐藏中央"));
centre.setVisible(false);
}
}
public static void main(String[] args)
{
HideButton app = new HideButton();
app.addWindowListener(new MyWindowListener());
}
}
//编译可以通过,但是运行时不正常,估计是setVisible的问题
...全文
相关推荐
warbrett-com
Warbrett-com 非常简单的博客/主页。 可能不适合一般用途,但一个很好的起点。 用途:Node、Express、Knex、Postgres、Jade、Passport、Marked、feed 等。 目前需要一些大规模的清理、设计更改(我指的是一般设计)和更好的管理系统。 Git 拉取 repo 安装 将 config-sample 重命名为 config,更新所有内容 npm 运行迁移 ……?
《模式识别与数据挖掘》配套PPT课件
《模式识别与数据挖掘》配套PPT课件
科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx
科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核
跨境电商供应链管理(AIGC版)课件+教案+参考答案
跨境电商供应链管理(AIGC版)课件+教案+参考答案


Java SE
