package untitled1;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Frame1 extends JFrame
{
private JPanel contentPane;
private XYLayout xYLayout1 = new XYLayout();
//my controls
private final int myLength = 5;
private final int mySize = 50;
private JLabel[][] myLabels = new JLabel[myLength][myLength]; //Construct the frame
public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(258, 278));
this.setTitle("Frame Title");
this.MyControlsInIt();
contentPane.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
contentPane_mouseClicked(e);
}
});
}
private void MyControlsInIt()
{
for (int i = 0; i < this.myLength; i++)
{
for (int j = 0; j < this.myLength; j++)
{
this.myLabels[i][j] = new JLabel();
this.myLabels[i][j].setBorder(BorderFactory.createRaisedBevelBorder());
contentPane.add(this.myLabels[i][j],
new XYConstraints (i*mySize, j*mySize, mySize, mySize)); }
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
} void contentPane_mouseClicked(MouseEvent e)
{
int i = e.getX()/this.mySize;
int j = e.getY()/this.mySize;
this.myLabels[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
this.myLabels[i][j].setForeground(Color.red);
this.myLabels[i][j].setText("clicked");
}
}
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Frame1 extends JFrame
{
private JPanel contentPane;
private XYLayout xYLayout1 = new XYLayout();
//my controls
private final int myLength = 5;
private final int mySize = 50;
private JLabel[][] myLabels = new JLabel[myLength][myLength]; //Construct the frame
public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(258, 278));
this.setTitle("Frame Title");
this.MyControlsInIt();
contentPane.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
contentPane_mouseClicked(e);
}
});
}
private void MyControlsInIt()
{
for (int i = 0; i < this.myLength; i++)
{
for (int j = 0; j < this.myLength; j++)
{
this.myLabels[i][j] = new JLabel();
this.myLabels[i][j].setBorder(BorderFactory.createRaisedBevelBorder());
contentPane.add(this.myLabels[i][j],
new XYConstraints (i*mySize, j*mySize, mySize, mySize)); }
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
} void contentPane_mouseClicked(MouseEvent e)
{
int i = e.getX()/this.mySize;
int j = e.getY()/this.mySize;
this.myLabels[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
this.myLabels[i][j].setForeground(Color.red);
this.myLabels[i][j].setText("clicked");
}
}
解决方案 »
- 关于JAVA画图的问题,各位筒子帮忙看下。
- 求解:new ReflectTester().copy(customer)
- 请教:用Java如何实现打印excel文件的功能啊。
- 奇怪,jTextField1在setText("")后就不能获得光标!
- 有关java编程思想的几个问题(1)
- socket 服务器端 大量CLOSE_WAIT 状态连接
- 关于serializable接口,在线等待
- 哪位大侠有关于流程控制中间件的相关文章和资料!!
- sharetop,新斑竹,回答我一个问题!很简单的!欢迎大家进来提问,让我们的新帮主解答,如果能回答10个,我就全力支持!发表对新斑竹的看法,发表者有分!
- 关于JAVA MAIL的一个问题。
- 关于jboss+tomcat与数据库连接测试结果,请大家讨论一下。。
- 问个很简单的问题:如何把一个double数值只保留前n位小数?急!!
package untitled1;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;/**
* <p>Title:一个小例子 </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author sky000
*/public class Frame1 extends JFrame
{
private JPanel contentPane;
private XYLayout xYLayout1 = new XYLayout();
//my controls 小心点
private final int myLength = 5;
private final int mySize = 50;
private JLabel[][] myLabels = new JLabel[myLength][myLength]; //Construct the frame
public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
//小心异常啊
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(258, 278));
this.setTitle("Frame Title");
this.MyControlsInIt();
contentPane.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
contentPane_mouseClicked(e);
}
});
}
private void MyControlsInIt()
{
for (int i = 0; i < this.myLength; i++)
{
for (int j = 0; j < this.myLength; j++)
{
this.myLabels[i][j] = new JLabel();
this.myLabels[i][j].setBorder(BorderFactory.createRaisedBevelBorder());
contentPane.add(this.myLabels[i][j],
new XYConstraints (i*mySize, j*mySize, mySize, mySize)); }
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
} void contentPane_mouseClicked(MouseEvent e)
{
int i = e.getX()/this.mySize;
int j = e.getY()/this.mySize;
this.myLabels[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
this.myLabels[i][j].setForeground(Color.red);
this.myLabels[i][j].setText("clicked");
}
}
///:~
不好意思,我只是把楼上的有些地方稍微改了一下。