java super()的使用问题
我的问题如下:
假设
[code=java]
package zxw_Login;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login_Vo extends JFrame{
JLayeredPane lay = new JLayeredPane();
JPanel jp = new JPanel();
ImageIcon image = new ImageIcon("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Sunset.jpg");
JLabel jb = new JLabel(image);
JFrame jf = null;
JPanel jp1 = null;
JPanel jp2 = null;
JLabel jl1 =null;
JLabel jl2 =null;
JLabel jl3 =null;
JLabel jl4 =null;
JTextField jt1 = null;
JPasswordField jt2 = null;
Choice ch = null;
Checkbox cb1 = null;
Checkbox cb2 = null;
JButton jb1 = null;
JButton jb2 = null;
JButton jb3 = null;
JButton jb4 = null;
Font font = null;
Login_Vo(){
this.setLayeredPane(lay);
// jf = new JFrame("欢迎光临在线商城");
this.setBounds(600,200,400,500);
this.setLayout(null);
this.setResizable(false);
this.setVisible(true);
jp.add(jb);
jp.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
jp.add(jb);
jp1 = new JPanel();
jp1.setBounds(0,0,400,100);
jp1.setBackground(Color.GREEN);
jl1 = new JLabel("欢迎光临在线商城",JLabel.CENTER);
font = new Font("华文彩云",0,40);
jl1.setForeground(Color.RED);
jl1.setFont(font);
jp2 = new JPanel();
jp2.setBounds(0,100,400,400);
jp2.setBackground(Color.WHITE);
jp2.setLayout(null);
jl2 = new JLabel("账号");
jl2.setBounds(100,50,80,20);
jt1 =new JTextField();
jt1.setBounds(200,50,120,20);
jl3 = new JLabel("密码");
jl3.setBounds(100,90,80,20);
jt2 = new JPasswordField();
jt2.setBounds(200,90,120,20);
jl4 = new JLabel("身份");
jl4.setBounds(100,130,120,20);
ch = new Choice();
ch.setBounds(200,130,120,40);
ch.add("普通用户");
ch.add("管理员");
cb1 = new Checkbox("记住密码");
cb1.setBounds(120,190,80,40);
cb2 = new Checkbox("自动登录");
cb2.setBounds(220,190,80,40);
jb1 = new JButton("确定");
jb1.setBounds(120,250,60,30);
jb2 = new JButton("重置");
jb2.setBounds(220,250,60,30);
jb3 = new JButton("用户注册");
jb3.setBounds(180,320,120,40);
jb4 = new JButton("退出");
jb4.setBounds(310,320,80,40);
jp1.add(jl1);
jp2.add(jl2);
jp2.add(jt1);
jp2.add(jl3);
jp2.add(jt2);
jp2.add(jl4);
jp2.add(ch);
jp2.add(cb1);
jp2.add(cb2);
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
jp1.setOpaque(false);
jp2.setOpaque(false);
// jf.add(jp1);
// jf.add(jp2);
lay.add(jp,JLayeredPane.DEFAULT_LAYER);
lay.add(jp1,JLayeredPane.MODAL_LAYER);
lay.add(jp2,JLayeredPane.MODAL_LAYER);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
jf.setVisible(false);
new Dh0104_ShopVo();
}
});
jb2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
jt1.setText(null);
jt2.setText(null);
}
});
jb3.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
jf.setVisible(false);
new Dh0104_ZhuceVo();
}
});
jb4.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
System.exit(0);
}
});
}
}[code]
问题有2个:
1、我这里的监听没用了,为什么?如何解决?
2、我怀疑是因为我直接继承了 extends 导致问题出现的,于是我尝试着用super().add(jb1);super().add(jb2);.......来把jb1~jb4这4个JButton加入JFrame,但是报错了,为什么?怎么改?
[解决办法]
Dh0104_ZhuceVo类呢?
[解决办法]
监听没有效果是么?
你先测试一下会不会是鼠标事件的问题,你把其中的一个,或者添加一个界面监听试试,看看有没有效果。
另外你添加的是双击事件,你会不会有可能点击了鼠标所以没有反应?
bt.addMouseListener(new MouseAdapter()//鼠标监听
55 {
56 private int count = 1;
57 private int mouseCount = 1;
58 public void mouseEntered(MouseEvent e)
59 {
60 System.out.println("鼠标监听"+count++);
61 }
62 public void mouseClicked(MouseEvent e)
63 {
64 if(e.getClickCount()==2)
65 System.out.println("鼠标被双击了");
66 else System.out.println("鼠标被点击"+mouseCount++);
67 }
68 });