关于开关问题 怎么实现??boolean start 怎么用?作用范围是怎样?下面要怎么改才能打出开始?谢谢。。。自学一旧云。。
public class sasdsd extends JFrame implements ActionListener {
JButton jButton;
boolean start=false;
public static void main(String[] args) {
sasdsd aSasdsd=new sasdsd();
aSasdsd.name();
}
public void name() {
jButton=new JButton("确定");
jButton.addActionListener(this);
this.add(jButton);
this.setSize(100, 100);
setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
System.out.println(this.start);
if (start) {
System.out.println("开始");
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
start=true;
System.out.println(this.start);
}
}
}
public class sasdsd extends JFrame implements ActionListener {
JButton jButton;
boolean start=false;
public static void main(String[] args) {
sasdsd aSasdsd=new sasdsd();
aSasdsd.name();
}
public void name() {
jButton=new JButton("确定");
jButton.addActionListener(this);
this.add(jButton);
this.setSize(100, 100);
setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
System.out.println(this.start);
if (start) {
System.out.println("开始");
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
start=true;
System.out.println(this.start);
}
}
}