JPanel上通过鼠标点击出现图形的问题
具体描述下问题:现在已有一个JPanel的对象,希望通过鼠标的点击,在鼠标点击到的位置,出现一个小的实心圆,应该要如何设置这段代码?拜托各位大神了。。。补充说明一下,我所...
具体描述下问题:现在已有一个JPanel的对象,希望通过鼠标的点击,在鼠标点击到的位置,出现一个小的实心圆,应该要如何设置这段代码?
拜托各位大神了。。。
补充说明一下,我所指的“鼠标点击”是指在JPanel的对象上直接点击,不是按JButton或者其他的按钮,就好像在纸上按手印的效果。。。
再谢一次各位大神了。。。 展开
拜托各位大神了。。。
补充说明一下,我所指的“鼠标点击”是指在JPanel的对象上直接点击,不是按JButton或者其他的按钮,就好像在纸上按手印的效果。。。
再谢一次各位大神了。。。 展开
2个回答
展开全部
e;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
public class HideButton extends JFrame {
private JPanel jPanel = null;
private JButton jButton = null;
/**
* This method initializes
*
*/
public HideButton() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setSize(new Dimension(239, 129));
this.setContentPane(getJPanel());
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(getJButton(), null);
}
return jPanel;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(72, 29, 109, 39));
jButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent e) {
jButton.setVisible(false);
}
public void mouseExited(java.awt.event.MouseEvent e) {
jButton.setVisible(true);
}
});
}
return jButton;
}
public static void main(String args[]){
new HideButton().setVisible(true);
}
}
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
public class HideButton extends JFrame {
private JPanel jPanel = null;
private JButton jButton = null;
/**
* This method initializes
*
*/
public HideButton() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setSize(new Dimension(239, 129));
this.setContentPane(getJPanel());
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(getJButton(), null);
}
return jPanel;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(72, 29, 109, 39));
jButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent e) {
jButton.setVisible(false);
}
public void mouseExited(java.awt.event.MouseEvent e) {
jButton.setVisible(true);
}
});
}
return jButton;
}
public static void main(String args[]){
new HideButton().setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class ImageJPanel extends JLabel implements MouseListener
{
public ImageJPanel()
{
this.setSize(100);
addMouseListener(this);
}
public void mouseDragged(MouseEvent e)
{
//鼠标事件
}
public void mousePressed(MouseEvent e)
{
//画圆老镇拦旅备
}
//侍胡略
}
public Test extends JFrame
{
JFrame jframe = new JFrame("test");
ImageJPanel jpanel = new ImageJpanel;
jframe.add(jpanel);
jpanel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
}
this.setSize(120);
}
{
public ImageJPanel()
{
this.setSize(100);
addMouseListener(this);
}
public void mouseDragged(MouseEvent e)
{
//鼠标事件
}
public void mousePressed(MouseEvent e)
{
//画圆老镇拦旅备
}
//侍胡略
}
public Test extends JFrame
{
JFrame jframe = new JFrame("test");
ImageJPanel jpanel = new ImageJpanel;
jframe.add(jpanel);
jpanel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
}
this.setSize(120);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询