JWindowr的闪烁问题
点一下按钮,这个JWindow 窗口闪下就没了,为什么会这样?
源程序如下:
请大侠帮忙看看:
package untitled;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Applet1 extends JApplet {
private boolean isStandalone = false;
JWindow jWindow1;
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JPanel jPanel2 = new JPanel();
JButton jButton2 = new JButton();
//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 Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
jWindow1=new JWindow();
jPanel1.setBackground(Color.white);
jButton1.setText("jButton1");
jButton1.addActionListener(new Applet1_jButton1_actionAdapter(this));
jPanel2.setBackground(Color.orange);
jPanel2.setLayout(null);
jButton2.setBounds(new Rectangle(124, 5, 73, 25));
jButton2.setText("jButton2");
jButton2.addActionListener(new Applet1_jButton2_actionAdapter(this));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jButton1, null);
jWindow1.getContentPane().add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jButton2, null);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
//static initializer for setting look & feel
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
void jButton1_actionPerformed(ActionEvent e) {
jWindow1.setSize(300,200);
jWindow1.setLocation(100,100);
jWindow1.setVisible(true);
jWindow1.pack();
jWindow1.show();
//jPanel2.repaint();
}
void jButton2_actionPerformed(ActionEvent e) {
jWindow1.dispose();
}
}
class Applet1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Applet1 adaptee;
Applet1_jButton1_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Applet1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Applet1 adaptee;
Applet1_jButton2_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
谢谢了。。
问题点数:50、回复次数:5Top
1 楼holilyboy(*会飞的猪*)回复于 2003-06-01 20:22:43 得分 0
upTop
2 楼mymoto(忽忽)回复于 2003-06-01 22:45:59 得分 40
把你的pack()去掉,那个是对布局重新整理,所以会闪烁Top
3 楼holilyboy(*会飞的猪*)回复于 2003-06-02 14:57:09 得分 0
那怎么加上标题栏呢?
Top
4 楼holilyboy(*会飞的猪*)回复于 2003-06-03 14:41:52 得分 0
还有
1、如何将该窗口始终最前呢?
2、如何去掉“Java Applet Window”字样呢?
一定给分。。
Top
5 楼mymoto(忽忽)回复于 2003-06-03 15:09:21 得分 10
具我所知
1、不知道,应该使用jni了吧
2、不能去掉Top




