本人初学JAVA,老师让编一个网吧收费系统(呵呵,类似的,不过是单机版的),我把界面做好了,想法是点击"上机"按钮,面板就换成上机面板,点击"下机"按钮,面板就换成下机面板,或者点击按钮弹出上机对话框或下机对话框也行,可以进行下一步的操作.
但是现在有一个问题,我点"上机"按钮或"下机"按钮时,面板也不切换,整了一下午也没整明白,恳请哪个高人指点一下,或者帮我把代码改一改,代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class NetBar extends JFrame
{
JButton upbut = new JButton("上机");
JButton downbut = new JButton("下机");
JButton setbut = new JButton("查询");
JButton helpbut = new JButton("帮助");
JTextArea ta = new JTextArea("欢迎使用");
JTextArea ta1 = new JTextArea("上机");
JTextArea ta2 = new JTextArea("下机");
JTextArea ta3 = new JTextArea("查询");
JTextArea ta4 = new JTextArea("帮助");
JPanel upPanel = new JPanel();
JPanel downPanel = new JPanel();
JPanel setPanel = new JPanel();
JPanel helpPanel = new JPanel();
JPanel p = new JPanel();
Container c=getContentPane();
public NetBar()
{
getContentPane().setLayout(new BorderLayout());
p.add(upbut);
p.add(downbut);
p.add(setbut);
p.add(helpbut);
upPanel.add(ta1);
downPanel.add(ta2);
setPanel.add(ta3);
helpPanel.add(ta4);
getContentPane().add(p,BorderLayout.NORTH);
getContentPane().add(ta,BorderLayout.CENTER);
getContentPane().add(upPanel,BorderLayout.CENTER);
getContentPane().add(downPanel,BorderLayout.CENTER);
getContentPane().add(setPanel,BorderLayout.CENTER);
getContentPane().add(helpPanel,BorderLayout.CENTER);
upbut.addActionListener(new Up());
}
public static void main(String []args)
{
NetBar nb = new NetBar();
nb.setTitle("网吧收费系统");
nb.setSize(400,400);
nb.show();
}
class Up implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("上机"))
{
//ta.setBackground(Color.red);
ta1.show(true);
ta.hide();
}
}
}
}