java编译ButtonEvent程序总是提示出错,代码如下
importjava.awt.*;importjava.awt.event.*;importjava.awing.*;publicclassButtonEventexte...
import java.awt. *;import java.awt.event.*;import java.awing.*;public class ButtonEvent extends JFrameimplements ActionListener{JButton button =new JButton("click me");JTextArea textArea = new JTextArea(2,20);Container c;int ClickCount=0;public ButtonEvent(){super("ButtonEvent.java;按钮事件测试");c=getContentPane();c.setLayout(new FlowLayout());c.add(button);c.add(textArea);setSize(300,120);show();button.addActionListener(this);}public void actionPerformed(ActionEvent e){ClickCount++;textArea.setText("您按click me" +clickCount+ "次");
public static void main(String[] args) { ButtonEvent app = new ButtonEvent(); app.addWindowListener(new MyWindowListener()); }}} 展开
public static void main(String[] args) { ButtonEvent app = new ButtonEvent(); app.addWindowListener(new MyWindowListener()); }}} 展开
3个回答
展开全部
是不是这种效果
import java.awt. *;
import java.awt.event.*;
import javax.swing.*;
public class ButtonEvent extends JFrame implements ActionListener{
JButton button =new JButton("click me");
JTextArea textArea = new JTextArea(2,20);
Container c;
int clickCount=0;
public ButtonEvent(){
super("ButtonEvent.java;按钮事件测试");
c=getContentPane();
c.setLayout(new FlowLayout());
c.add(button);
c.add(textArea);
setSize(300,120);
show();
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
clickCount++;
textArea.setText("您按click me" +clickCount+ "次");
}
public static void main(String[] args) {
ButtonEvent app = new ButtonEvent();
//app.addWindowListener(new MyWindowListener());
}
}
import java.awt. *;
import java.awt.event.*;
import javax.swing.*;
public class ButtonEvent extends JFrame implements ActionListener{
JButton button =new JButton("click me");
JTextArea textArea = new JTextArea(2,20);
Container c;
int clickCount=0;
public ButtonEvent(){
super("ButtonEvent.java;按钮事件测试");
c=getContentPane();
c.setLayout(new FlowLayout());
c.add(button);
c.add(textArea);
setSize(300,120);
show();
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
clickCount++;
textArea.setText("您按click me" +clickCount+ "次");
}
public static void main(String[] args) {
ButtonEvent app = new ButtonEvent();
//app.addWindowListener(new MyWindowListener());
}
}
2012-09-23
展开全部
public void actionPerformed(ActionEvent e)
{ //要加if 吧
ClickCount++;
textArea.setText("您按click me" +clickCount+ "次"); ///这里的括号呢?
public static void main(String[] args)
{
ButtonEvent app = new ButtonEvent();
app.addWindowListener(new MyWindowListener());
}
}
}
{ //要加if 吧
ClickCount++;
textArea.setText("您按click me" +clickCount+ "次"); ///这里的括号呢?
public static void main(String[] args)
{
ButtonEvent app = new ButtonEvent();
app.addWindowListener(new MyWindowListener());
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-09-23
展开全部
出现了很多错误耶.....导入的包名写错了,大小写写错了。花括号括错了......还有,监听器类你没有写。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询