JButton的toString都显示的什么?
我的一个panel中包含了许多JButton,我看其中的两个JButton的toString返回值,分别是
java.awt.event.MouseEvent[MOUSE_CLICKED,(32,17),button=1,modifiers=Button1,clickCount=1] on javax.swing.JButton[,330,28,66x28,layout=javax.swing.OverlayLayout,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@120bf2c,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=%,defaultCapable=true]
和
java.awt.event.MouseEvent[MOUSE_CLICKED,(31,19),button=1,modifiers=Button1,clickCount=1] on javax.swing.JButton[,264,0,66x28,layout=javax.swing.OverlayLayout,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@120bf2c,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource
[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=/,defaultCapable=true]
请问,"MOUSE_CLICKED,("后的(31,19)和(32,17)分别代表什么意思,还有其他的许多各个项都代表什么意思?
问题点数:0、回复次数:11Top
1 楼jamesfancy(▲) 边城狂人 <Java|C++] (★)回复于 2004-11-03 23:03:42 得分 0
(31,19) 可能是鼠标点的位置。
这些信息没有必须去全搞明白的,搞明白了对你也没有多大用处。Top
2 楼hotheartlewis()回复于 2004-11-04 09:13:31 得分 0
是这样的,我自己从JButton中派生了一个类MyButton,想实现这样的功能,当按下这类按钮时,使按钮失效,同时作其他工作,但现在鼠标按下按钮的工作写在什么函数里呢,是写在mouseclick中还是什么函数中呢?程序如下。
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
import java.lang.Throwable;
public class BattleShip extends JFrame
{
public static void main(String[] args)
{
BattleShip bs = new BattleShip("BS");
}
BattleShip(String str)
{
super(str);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(450, 450);
initPanelAndButtons();
setResizable(false);
setVisible(true);
}
void initPanelAndButtons()
{
JPanel jPanel = new JPanel();
BsButton myB[]=new BsButton[25];
int i;/*
for (i=0; i<myB.length; i++)
{
myB[i] = new BsButton("");
myB[i].setFlag(0);
myB[i].setPreferredSize(new java.awt.Dimension(70, 70));
jPanel.add(myB[i]);
}
*/
BsButton m = new BsButton("34");
jPanel.add(m);
getContentPane().add(jPanel, java.awt.BorderLayout.CENTER);
}
//button
class BsButton extends JButton
{
int flag; //0:no any 2:one of the group of 2 battleships; 3:one of the group of 3 battleships;
BsButton(String str)
{
super(str);
flag = 0; //default value
}
//set flag
public void setFlag(int iFlag)
{
flag = iFlag;
}
public int getFlag()
{
return flag;
}
public void BsButtonMouseClicked(java.awt.event.ActionEvent evt)
{
System.out.println("ffd");
this.setEnabled(false);
JOptionPane jOP = new JOptionPane();
jOP.showMessageDialog(this, "11", "22", JOptionPane.INFORMATION_MESSAGE);
}
}
}
class RetryButton extends JButton
{
RetryButton()
{
super();
}
private void RetryButtonActionPerformed(java.awt.event.ActionEvent evt)
{
}
}
Top
3 楼hotheartlewis()回复于 2004-12-09 16:10:03 得分 0
接分Top
4 楼hotheartlewis()回复于 2004-12-09 16:10:51 得分 0
为什么给不了分儿呢?Top
5 楼lidi3503(我来也)回复于 2004-12-09 17:37:40 得分 0
你要给自己分?????
我晕!!Top
6 楼hotheartlewis()回复于 2004-12-28 16:44:14 得分 0
不是要给自己分,是我登陆后,别的贴子都可以结贴,为什么这个贴子总说我还没有登录呢?Top
7 楼hotheartlewis()回复于 2005-03-03 10:37:53 得分 0
?Top
8 楼zxmzfbdc(也速该把阿秃儿)回复于 2005-03-03 11:51:08 得分 0
打印出的东东是JButton重载了Object的toString方法,至于具体包含什么东西,最好去看源代码。
要想监听一个事件,必须向监听器注册,并重栽其中相应的方法
例如,想让一个button点击使之失效的代码如下:
/*
* Created on 2004-11-24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package cn.zxm.xml.dom;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class FibonacciDOMClient
{
JButton button = new JButton("aaaa");
private void test()
{
JFrame frame = new JFrame("");
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = frame.getContentPane();
c.add(button,BorderLayout.CENTER);
frame.setVisible(true);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FibonacciDOMClient.this.button.setText("safsaf");
}
}
);
}
public static void main(String[] args)
{
app.test();
//System.out.println("button ======= " + button.toString());
}
}
Top
9 楼zxmzfbdc(也速该把阿秃儿)回复于 2005-03-03 11:53:31 得分 0
更正test方法修改如下:
private void test()
{
JFrame frame = new JFrame("");
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = frame.getContentPane();
c.add(button,BorderLayout.CENTER);
frame.setVisible(true);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FibonacciDOMClient.this.button.setEnabled(false);
//在这里加入想处理的代码
}
}
);
}
Top
10 楼lishangyong(英子)回复于 2005-03-06 21:06:27 得分 0
那个值是JButton的大小设置呀.
Top
11 楼hotheartlewis()回复于 2005-03-20 16:28:37 得分 0
?Top




