Java 窗体事件
以下是我自己写的一段窗体事件的代码,我自己仔细看了几遍,觉得没有写错,但是Eclipse报错,我是新人,刚学Java没多久,请高手指点一下~importjava.awt....
以下是我自己写的一段窗体事件的代码,我自己仔细看了几遍,觉得没有写错,但是Eclipse报错,我是新人,刚学Java没多久,请高手指点一下~
import java.awt.event.WindowFocusListener;
import javax.swing.*;
public class WindowEvent extends JFrame{
public static void main(){
WindowEvent frame = new WindowEvent();
frame.setVisible(true);
}
public WindowEvent(){
super();
addWindowFocusListener( new MYWindowFocusListener());
setTitle("WindowEvent");
setBounds(100,100,500,375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MYWindowFocusListener() implements WindowFocusListener{
public void windowGainedFocus(WindowEvent e){
}
public void windowLostFocus(WindowEvent e){
}
}
}
如果能帮我讲解一下,会再追加分数的 展开
import java.awt.event.WindowFocusListener;
import javax.swing.*;
public class WindowEvent extends JFrame{
public static void main(){
WindowEvent frame = new WindowEvent();
frame.setVisible(true);
}
public WindowEvent(){
super();
addWindowFocusListener( new MYWindowFocusListener());
setTitle("WindowEvent");
setBounds(100,100,500,375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MYWindowFocusListener() implements WindowFocusListener{
public void windowGainedFocus(WindowEvent e){
}
public void windowLostFocus(WindowEvent e){
}
}
}
如果能帮我讲解一下,会再追加分数的 展开
4个回答
展开全部
import java.awt.event.*;
import javax.swing.*;
public class WindowEvent extends JFrame{
public static void main(){
WindowEvent frame = new WindowEvent();
frame.setVisible(true);
}
public WindowEvent(){
super();
addWindowFocusListener( new MYWindowFocusListener());
setTitle("WindowEvent");
setBounds(100,100,500,375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MYWindowFocusListener implements WindowFocusListener{
public void windowGainedFocus(java.awt.event.WindowEvent e) {
}
public void windowLostFocus(java.awt.event.WindowEvent e) {
}
}
}
private class MYWindowFocusListener() implements WindowFocusListener{
MYWindowFocusListener是个内部类 后面不能加()它是类不是方法,应该是
private class MYWindowFocusListener implements WindowFocusListener{
import javax.swing.*;
public class WindowEvent extends JFrame{
public static void main(){
WindowEvent frame = new WindowEvent();
frame.setVisible(true);
}
public WindowEvent(){
super();
addWindowFocusListener( new MYWindowFocusListener());
setTitle("WindowEvent");
setBounds(100,100,500,375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MYWindowFocusListener implements WindowFocusListener{
public void windowGainedFocus(java.awt.event.WindowEvent e) {
}
public void windowLostFocus(java.awt.event.WindowEvent e) {
}
}
}
private class MYWindowFocusListener() implements WindowFocusListener{
MYWindowFocusListener是个内部类 后面不能加()它是类不是方法,应该是
private class MYWindowFocusListener implements WindowFocusListener{
展开全部
class MYWindowFocusListener 后不应加括号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
addWindowFocusListener( new MYWindowFocusListener()
{
//这里不感觉少点东西吗?
//写上你的处理事件函数.
}
);
{
//这里不感觉少点东西吗?
//写上你的处理事件函数.
}
);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
您的main()函数没有跟参数,改成这样试:
public static void main(String[] args) {
//您的代码
}
public static void main(String[] args) {
//您的代码
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询