import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;public class DemoUI extends JFrame implements ActionListener
{
private JPanel toolBar;
private JPanel actionPanel;
private JPanel contentPanel;
private JButton about;
private JButton help;
public DemoUI()
{
this.setSize(600,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("Demo");
toolBar = new JPanel();
toolBar.setBackground(new Color(45,112,162));
toolBar.setPreferredSize(new Dimension(600,40));
actionPanel = new JPanel();
actionPanel.setBackground(Color.yellow);
actionPanel.setPreferredSize(new Dimension(150,360));
contentPanel = new JPanel();
contentPanel.setBackground(Color.blue);
contentPanel.setPreferredSize(new Dimension(450,360));
this.getContentPane().add(toolBar, BorderLayout.NORTH);
this.getContentPane().add(actionPanel,BorderLayout.EAST);
this.getContentPane().add(contentPanel,BorderLayout.CENTER);
about = new JButton("关于");
help = new JButton("帮助");
toolBar.add(help);
toolBar.add(about);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == about)
{
JOptionPane.showMessageDialog(this,"作者","关于",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource() == help)
{
JOptionPane.showMessageDialog(this,"帮助","帮助",JOptionPane.INFORMATION_MESSAGE);
}
} public static void main(String[] args) throws HeadlessException
{
DemoUI demoUI = new demoUI();
demoUI.show(); }}请教高人,当点击"关于"或者"帮助"的时候不能弹出对话框,是为什么啊
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;public class DemoUI extends JFrame implements ActionListener
{
private JPanel toolBar;
private JPanel actionPanel;
private JPanel contentPanel;
private JButton about;
private JButton help;
public DemoUI()
{
this.setSize(600,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("Demo");
toolBar = new JPanel();
toolBar.setBackground(new Color(45,112,162));
toolBar.setPreferredSize(new Dimension(600,40));
actionPanel = new JPanel();
actionPanel.setBackground(Color.yellow);
actionPanel.setPreferredSize(new Dimension(150,360));
contentPanel = new JPanel();
contentPanel.setBackground(Color.blue);
contentPanel.setPreferredSize(new Dimension(450,360));
this.getContentPane().add(toolBar, BorderLayout.NORTH);
this.getContentPane().add(actionPanel,BorderLayout.EAST);
this.getContentPane().add(contentPanel,BorderLayout.CENTER);
about = new JButton("关于");
help = new JButton("帮助");
toolBar.add(help);
toolBar.add(about);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == about)
{
JOptionPane.showMessageDialog(this,"作者","关于",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource() == help)
{
JOptionPane.showMessageDialog(this,"帮助","帮助",JOptionPane.INFORMATION_MESSAGE);
}
} public static void main(String[] args) throws HeadlessException
{
DemoUI demoUI = new demoUI();
demoUI.show(); }}请教高人,当点击"关于"或者"帮助"的时候不能弹出对话框,是为什么啊
在help = new JButton("帮助");后面加上下面两句就可以了
about.addActionListener(this);
help.addActionListener(this);