java swing的一个小问题
用swing里的JFrame写了个窗口谁能告诉我怎么在点按钮后弹出一个新的窗口??代码:importjava.awt.*;importjava.awt.event.*;i...
用swing里的JFrame写了个窗口 谁能告诉我怎么在点按钮后弹出一个新的窗口??
代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
求高手呀!!!!
图在下面: 展开
代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
求高手呀!!!!
图在下面: 展开
2个回答
展开全部
弹出什么窗口啊,对话框? 中间按钮添加了事件。
package tree2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame implements ActionListener
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.addActionListener(this);
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("随便写:");
if(name != null){
System.out.println("是不:" + name);
}
}
}
package tree2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame implements ActionListener
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.addActionListener(this);
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("随便写:");
if(name != null){
System.out.println("是不:" + name);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询