当前位置: 技术问答>java相关
如何自定义一个对话框,然后在Applet中弹出该对话框(模式)
来源: 互联网 发布时间:2015-01-05
本文导语: 如题!!!!!!!!! | 不知道是不是你想要的? import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import com.borland.jbcl.layout.*; public class Applet1 extends JApplet { Fram...
如题!!!!!!!!!
|
不知道是不是你想要的?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Applet1 extends JApplet {
Frame frame = new Frame();
boolean isStandalone = false;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = 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 {
jButton1.setText("jButton1");
jButton1.addActionListener(new Applet1_jButton1_actionAdapter(this));
xYLayout1.setWidth(252);
xYLayout1.setHeight(194);
this.getContentPane().setLayout(xYLayout1);
this.setForeground(new Color(112, 105, 190));
this.getContentPane().setBackground(new Color(85, 92, 217));
this.getContentPane().add(jButton1, new XYConstraints(83, 141, -1, -1));
}
/**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) {
Dialog1 dlg = new Dialog1( frame, "关于本软件", true );
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y+12);
dlg.setSize(new Dimension(300, 200));
dlg.setModal( true );
dlg.show();
}
}
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);
}
}
import java.awt.*;
import javax.swing.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
public class Dialog1 extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
public Dialog1(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public Dialog1() {
this(null, "", false);
}
void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
getContentPane().add(panel1);
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Applet1 extends JApplet {
Frame frame = new Frame();
boolean isStandalone = false;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = 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 {
jButton1.setText("jButton1");
jButton1.addActionListener(new Applet1_jButton1_actionAdapter(this));
xYLayout1.setWidth(252);
xYLayout1.setHeight(194);
this.getContentPane().setLayout(xYLayout1);
this.setForeground(new Color(112, 105, 190));
this.getContentPane().setBackground(new Color(85, 92, 217));
this.getContentPane().add(jButton1, new XYConstraints(83, 141, -1, -1));
}
/**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) {
Dialog1 dlg = new Dialog1( frame, "关于本软件", true );
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y+12);
dlg.setSize(new Dimension(300, 200));
dlg.setModal( true );
dlg.show();
}
}
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);
}
}
import java.awt.*;
import javax.swing.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
public class Dialog1 extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
public Dialog1(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public Dialog1() {
this(null, "", false);
}
void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
getContentPane().add(panel1);
}
}