学JAVA的过程中我遇到了N多问题,有的时候搞不懂就想来这里问问大家,
可是每个问题发一贴简直太不人道了,因为我的问题多,那样会发很多帖子,会把大家的帖子全都灌下去。
为了不影响大家我只好把我所有的问题都放到这一个帖子里提问,当然如果大家有什么问题也可以在这里问,我欢迎。
好了先问个嗷嗷简单的问题吧
为什么“The world”是不合法的变量名称?是因为中间多了个空格?
[此贴子已经被作者于2006-2-15 21:01:09编辑过]
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class C231 extends JFrame implements MouseListener
{
public static void main(String[] args)
{
C231 frame1 = new C231();
int px,py,px2,py2;
JLabel lb1;
JButton bu1;
public C231()
{
super("C231");
Container c = getContentPane();
c.setLayout(null);
lb1 = new JLabel("鼠标状态");
lb1.setFont(new Font("仿宋",Font.BOLD,20));
lb1.setForeground(Color.red);
lb1.setSize(200,28);
lb1.setLocation(10,10);
c.add(lb1);
bu1 = new JButton("鼠标按键区");
bu1.setSize(100,100);
bu1.setLocation(100,100);
bu1.addMouseListener(this);
c.add(bu1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,400);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
lb1.setText("按下鼠标键");
}
public void mouseReleased(MouseEvent e)
{
lb1.setText("释放鼠标键");
}
public void mouseEntered(MouseEvent e)
{
lb1.setText("进入按键区");
}
public void mouseExited(MouseEvent e)
{
lb1.setText("鼠标离开按键区");
}
public void mouseClicked(MouseEvent e)
{
lb1.setText("按了一下鼠标键");
}
}
}
请大家帮我找找程序的错误
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class C231 extends JFrame implements MouseListener
{
int px,py,px2,py2;
JLabel lb1;
JButton bu1;
public C231()
{
super("C231");
Container c = getContentPane();
c.setLayout(null);
lb1 = new JLabel("鼠标状态");
lb1.setFont(new Font("仿宋",Font.BOLD,20));
lb1.setForeground(Color.red);
lb1.setSize(200,28);
lb1.setLocation(10,10);
c.add(lb1);
bu1 = new JButton("鼠标按键区");
bu1.setSize(100,100);
bu1.setLocation(100,100);
bu1.addMouseListener(this);
c.add(bu1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,400);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
lb1.setText("按下鼠标键");
}
public void mouseReleased(MouseEvent e)
{
lb1.setText("释放鼠标键");
}
public void mouseEntered(MouseEvent e)
{
lb1.setText("进入按键区");
}
public void mouseExited(MouseEvent e)
{
lb1.setText("鼠标离开按键区");
}
public void mouseClicked(MouseEvent e)
{
lb1.setText("按了一下鼠标键");
}
public static void main(String[] args)
{
C231 frame1 = new C231();
}
}
你把构造函数放到main函数里去了,现在帮你改回来了
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class C231 extends JFrame implements MouseListener
{
int px,py,px2,py2;
JLabel lb1;
JButton bu1;
public C231()
{
super(\"C231\");
Container c = getContentPane();
c.setLayout(null);
lb1 = new JLabel(\"鼠标状态\");
lb1.setFont(new Font(\"仿宋\",Font.BOLD,20));
lb1.setForeground(Color.red);
lb1.setSize(200,28);
lb1.setLocation(10,10);
c.add(lb1);
bu1 = new JButton(\"鼠标按键区\");
bu1.setSize(100,100);
bu1.setLocation(100,100);
bu1.addMouseListener(this);
c.add(bu1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,400);
setVisible(true);
}
public static void main(String[] args)
{
C231 frame1 = new C231();
}
public void mousePressed(MouseEvent e)
{
lb1.setText(\"按下鼠标键\");
}
public void mouseReleased(MouseEvent e)
{
lb1.setText(\"释放鼠标键\");
}
public void mouseEntered(MouseEvent e)
{
lb1.setText(\"进入按键区\");
}
public void mouseExited(MouseEvent e)
{
lb1.setText(\"鼠标离开按键区\");
}
public void mouseClicked(MouseEvent e)
{
lb1.setText(\"按了一下鼠标键\");
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class C231 extends JFrame implements MouseListener
{
public static void main(String[] args)
{
C231 frame1 = new C231();
}
int px,py,px2,py2;
JLabel lb1;
JButton bu1;
public C231()
{
super("C231");
Container c = getContentPane();
c.setLayout(null);
lb1 = new JLabel("鼠标状态");
lb1.setFont(new Font("仿宋",Font.BOLD,20));
lb1.setForeground(Color.red);
lb1.setSize(200,28);
lb1.setLocation(10,10);
c.add(lb1);
bu1 = new JButton("鼠标按键区");
bu1.setSize(100,100);
bu1.setLocation(100,100);
bu1.addMouseListener(this);
c.add(bu1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,400);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
lb1.setText("按下鼠标键");
}
public void mouseReleased(MouseEvent e)
{
lb1.setText("释放鼠标键");
}
public void mouseEntered(MouseEvent e)
{
lb1.setText("进入按键区");
}
public void mouseExited(MouseEvent e)
{
lb1.setText("鼠标离开按键区");
}
public void mouseClicked(MouseEvent e)
{
lb1.setText("按了一下鼠标键");
}
}