当前位置: 技术问答>java相关
提问个关于GUI的问题!
来源: 互联网 发布时间:2015-04-23
本文导语: Frame上有两个label,一个(label1)显示,一个(label2)隐藏,点label1可以控制 label2的显示隐藏,可是这只有在窗体大小出现变化后才出现效果,why?我调用了 repaint()了!! 代码如下: package tree; import java.awt.*; import jav...
Frame上有两个label,一个(label1)显示,一个(label2)隐藏,点label1可以控制
label2的显示隐藏,可是这只有在窗体大小出现变化后才出现效果,why?我调用了
repaint()了!!
代码如下:
package tree;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.borland.jbcl.layout.*;
public class Applet2 extends Applet {
boolean isStandalone = false;
Label label1 = new Label();
Label label2 = new Label();
XYLayout xYLayout1 = new XYLayout();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public Applet2() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
label1.setText("label1");
label1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
label1_mouseClicked(e);
}
public void mouseEntered(MouseEvent e) {
label1_mouseEntered(e);
}
});
this.setLayout(xYLayout1);
label2.setText("label2");
label2.setVisible(false);
this.add(label1, new XYConstraints(183, 5, -1, -1));
this.add(label2, new XYConstraints(0, 0, 0, 0));
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
}
/**Destroy the applet*/
public void destroy() {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
void label1_mouseClicked(MouseEvent e) {
label2.setVisible(!label2.isVisible());
repaint();
}
void label1_mouseEntered(MouseEvent e) {
label1.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
label2的显示隐藏,可是这只有在窗体大小出现变化后才出现效果,why?我调用了
repaint()了!!
代码如下:
package tree;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.borland.jbcl.layout.*;
public class Applet2 extends Applet {
boolean isStandalone = false;
Label label1 = new Label();
Label label2 = new Label();
XYLayout xYLayout1 = new XYLayout();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public Applet2() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
label1.setText("label1");
label1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
label1_mouseClicked(e);
}
public void mouseEntered(MouseEvent e) {
label1_mouseEntered(e);
}
});
this.setLayout(xYLayout1);
label2.setText("label2");
label2.setVisible(false);
this.add(label1, new XYConstraints(183, 5, -1, -1));
this.add(label2, new XYConstraints(0, 0, 0, 0));
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
}
/**Destroy the applet*/
public void destroy() {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
void label1_mouseClicked(MouseEvent e) {
label2.setVisible(!label2.isVisible());
repaint();
}
void label1_mouseEntered(MouseEvent e) {
label1.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
|
可能是布局出问题了。
各个控件validate一次。行不行。
各个控件validate一次。行不行。