查一查Label的函数应该有相关方法
解决方案 »
- 如何把Date类换成calendar 类取得当前时间
- 探索java匿名类的实质
- 问个迷糊的问题,
- java里面输入输出流的一个乱码问题
- 帮忙看看这个问题,有关模式的问题,高分相送
- 请高手指点,从C++到Java必碰到的问题
- 如何由将一个4字节大小的数组中存放的值转换为类型为int变量的值?
- 出于简便,想多个请求对应一个action实例,那我在action中如何区分不同的请求?
- !!!急~请教JDBC时时查询ORACLE数据库某表的问题!
- byte[] 字节数组应该怎么出入mysql
- 急,java文件打成cab文件用什么工具,我用cabinet打成的包不能用。
- 如何转换子串String 中的 回车,换行 字符?
调用label1.setOpaque(true);label2.setOpaque(true);
2: 生成一个JLayeredPane: layeredPane
3:调用layeredPane.add(label1,0);
layeredPane.add(label2,1);
4: 在程序中添加一个按钮,用来切换label的层次,在事件处理函数中:
调用layeredPane.setLayer(Component,layer,position)
package untitled31;
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();
private JTabbedPane jTabbedPane1 = new JTabbedPane();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
JTabbedPane jTbPnBase = new JTabbedPane();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(506, 369));
this.setTitle("Frame Title");
jLabel1.setText("jLabel1");
jLabel2.setText("jLabel2");
contentPane.add(jTabbedPane1, new XYConstraints(14, 123, 234, 229));
contentPane.add(jLabel1, new XYConstraints(138, 58, 86, 25));
contentPane.add(jLabel2, new XYConstraints(288, 30, 167, 242));
jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
jLabel1_mouseDragged(e);
}
});
JPanel jPnlTask = new JPanel(new FlowLayout());
jTabbedPane1.add("Task", jPnlTask);
jPnlTask.add(jLabel1);
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jLabel1_mouseDragged(MouseEvent e){
jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR));
jLabel1.setLocation(jLabel1.getX() +e.getX(),jLabel1.getY() +e.getY());
//contentPane.add(jLabel1);
//contentPane.add(jTabbedPane1);
//contentPane.add(jLabel2); }
}
这个容器之外的。既然label1是移动的,不妨退一步。我这里有个演示程序
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;public class Frame1 extends JFrame
{
private JTabbedPane jTabbedPane1 = new JTabbedPane();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private XYLayout xYLayout1 = new XYLayout(); public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {jbInit(); }
catch(Exception e) {e.printStackTrace();}
}
private void jbInit() throws Exception
{
JLayeredPane layerPane=new JLayeredPane();
layerPane.setLayout(xYLayout1);
this.setSize(new Dimension(506, 369));
this.setTitle("Frame Title"); jLabel1.setOpaque(true);
jLabel1.setText("jLabel1");
jLabel2.setOpaque(true);
jLabel2.setText("jLabel2");
jLabel2.setBackground(Color.blue);
jLabel1.setBackground(Color.cyan);
layerPane.add(jTabbedPane1, new XYConstraints(14, 123, 234, 229),1);
layerPane.add(jLabel2,new XYConstraints(288, 30, 167, 242),2);
layerPane.add(jLabel1,new XYConstraints(108, 158, 86, 25),0);
jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e) {jLabel1_mouseDragged(e);}
});
layerPane.setPreferredSize(new Dimension(300, 310));
JPanel p=new JPanel();
jTabbedPane1.add("Task",p);
this.getContentPane().add(layerPane);
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0);
}
void jLabel1_mouseDragged(MouseEvent e)
{
jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR));
jLabel1.setLocation(jLabel1.getX() +e.getX(),jLabel1.getY() +e.getY());
}
public static void main(String [] args)
{
Frame1 f=new Frame1();
f.show();
}
}