先点击"输入"菜单,再点击"选择"
如何能在点击"选择"
的时候把"输入"菜单产生的Label去掉???
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;import java.sql.*;public class sale
extends JFrame
implements ActionListener {
JPanel inputJPanel;
JMenuBar mubar;
JMenu inputmu;
JMenuItem inputmuit,semuit; //inputmuitJButton ookJButton; inpt inp;
sele se;
JButton okJButton, nextJButton;
JTextField sumJTextField;
public sale() {
createUserInterface();
} // create and position GUI components
private void createUserInterface() { inp=new inpt(this);
se=new sele(this);
this.getContentPane().add(inp, BorderLayout.WEST);
this.getContentPane().add(se, BorderLayout.EAST); mubar = new JMenuBar();
setJMenuBar(mubar);
inputmu = new JMenu("输入");
inputmu.setFont(new Font("SansSerif", Font.PLAIN, 15));
mubar.add(inputmu);
inputmuit = new JMenuItem("输入");
semuit = new JMenuItem("选择");
inputmuit.setFont(new Font("SansSerif", Font.PLAIN, 15));
inputmu.add(inputmuit);
inputmu.add(semuit);
inputmuit.addActionListener(inp); semuit.addActionListener(se); setTitle("sale"); // set title bar text
setSize(435, 390); // set window size
setVisible(true); // display window } private void okJButtonactionPerformed(ActionEvent e) { sumJTextField.setText("");
} public void actionPerformed(ActionEvent e) { } public static void main(String[] args) {
sale application = new sale(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } // end method main
}
//input
class inpt extends JPanel implements ActionListener {JLabel datefromJLabel, datetoJLabel; sale s; inpt(sale s) {
this.s = s;
createUserInterface(); }
private void createUserInterface() {
datefromJLabel = new JLabel("日期从");
datefromJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
datefromJLabel.setVisible(false); add(datefromJLabel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == s.inputmuit)
datefromJLabel.setVisible(true);
} }class sele extends JPanel implements ActionListener {
JButton okJButton;
JLabel datefromJLabel, datetoJLabel;
JComboBox datefromyJComboBox,datefrommJComboBox,datetoyJComboBox;
sale s; sele(sale s) {
this.s = s;
createUserInterface(); }
private void createUserInterface() {
datefromJLabel = new JLabel("日期从");
datefromJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
datefromJLabel.setVisible(false); add( datefromJLabel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == s.inputmuit)
okJButton.setVisible(true); datefromJLabel.setVisible(true);
} }
如何能在点击"选择"
的时候把"输入"菜单产生的Label去掉???
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;import java.sql.*;public class sale
extends JFrame
implements ActionListener {
JPanel inputJPanel;
JMenuBar mubar;
JMenu inputmu;
JMenuItem inputmuit,semuit; //inputmuitJButton ookJButton; inpt inp;
sele se;
JButton okJButton, nextJButton;
JTextField sumJTextField;
public sale() {
createUserInterface();
} // create and position GUI components
private void createUserInterface() { inp=new inpt(this);
se=new sele(this);
this.getContentPane().add(inp, BorderLayout.WEST);
this.getContentPane().add(se, BorderLayout.EAST); mubar = new JMenuBar();
setJMenuBar(mubar);
inputmu = new JMenu("输入");
inputmu.setFont(new Font("SansSerif", Font.PLAIN, 15));
mubar.add(inputmu);
inputmuit = new JMenuItem("输入");
semuit = new JMenuItem("选择");
inputmuit.setFont(new Font("SansSerif", Font.PLAIN, 15));
inputmu.add(inputmuit);
inputmu.add(semuit);
inputmuit.addActionListener(inp); semuit.addActionListener(se); setTitle("sale"); // set title bar text
setSize(435, 390); // set window size
setVisible(true); // display window } private void okJButtonactionPerformed(ActionEvent e) { sumJTextField.setText("");
} public void actionPerformed(ActionEvent e) { } public static void main(String[] args) {
sale application = new sale(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } // end method main
}
//input
class inpt extends JPanel implements ActionListener {JLabel datefromJLabel, datetoJLabel; sale s; inpt(sale s) {
this.s = s;
createUserInterface(); }
private void createUserInterface() {
datefromJLabel = new JLabel("日期从");
datefromJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
datefromJLabel.setVisible(false); add(datefromJLabel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == s.inputmuit)
datefromJLabel.setVisible(true);
} }class sele extends JPanel implements ActionListener {
JButton okJButton;
JLabel datefromJLabel, datetoJLabel;
JComboBox datefromyJComboBox,datefrommJComboBox,datetoyJComboBox;
sale s; sele(sale s) {
this.s = s;
createUserInterface(); }
private void createUserInterface() {
datefromJLabel = new JLabel("日期从");
datefromJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
datefromJLabel.setVisible(false); add( datefromJLabel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == s.inputmuit)
okJButton.setVisible(true); datefromJLabel.setVisible(true);
} }
JCombobox,JTextfield......