javaswing鼠标事件问题
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassztlextendsJFra...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ztl extends JFrame
{Container c=getContentPane();
JLabel lb;
Image image;
public ztl(){
ImageIcon img=new ImageIcon("me.gif");
lb=new JLabel(img);
add(lb,BorderLayout.CENTER);
setSize(800,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);}
public void mousePressed(MouseEvent e)
{
setVisible(false);
}
public static void main(String as[]){
new ztl();
}
}
我想做一个程序。按住左键才能显示图像,松开就无法显示,求改进,这个不能跑
或者按住左键图像就消失了 展开
import java.awt.event.*;
import javax.swing.*;
public class ztl extends JFrame
{Container c=getContentPane();
JLabel lb;
Image image;
public ztl(){
ImageIcon img=new ImageIcon("me.gif");
lb=new JLabel(img);
add(lb,BorderLayout.CENTER);
setSize(800,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);}
public void mousePressed(MouseEvent e)
{
setVisible(false);
}
public static void main(String as[]){
new ztl();
}
}
我想做一个程序。按住左键才能显示图像,松开就无法显示,求改进,这个不能跑
或者按住左键图像就消失了 展开
展开全部
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class HideShow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JButton button, button1;
public HideShow() {
setLayout(new BorderLayout());
button = new JButton("aa");
button1 = new JButton("bb");
button1.setVisible(false);
button.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
button1.setVisible(true);
}
public void mouseReleased(MouseEvent e) {
button1.setVisible(false);
}
});
this.add(button, BorderLayout.NORTH);
this.add(button1, BorderLayout.SOUTH);
}
public static void main(String[] args) {
HideShow hs = new HideShow();
hs.setSize(500, 500);
hs.setVisible(true);
hs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
自己把button1换成图片吧~~~
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class HideShow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JButton button, button1;
public HideShow() {
setLayout(new BorderLayout());
button = new JButton("aa");
button1 = new JButton("bb");
button1.setVisible(false);
button.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
button1.setVisible(true);
}
public void mouseReleased(MouseEvent e) {
button1.setVisible(false);
}
});
this.add(button, BorderLayout.NORTH);
this.add(button1, BorderLayout.SOUTH);
}
public static void main(String[] args) {
HideShow hs = new HideShow();
hs.setSize(500, 500);
hs.setVisible(true);
hs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
自己把button1换成图片吧~~~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询