MyEclipse的Swing项目怎么不出来,要疯了。

2025-05-14 23:32:14
推荐回答(3个)
回答1:

直接 写代码就好了,写完代码,直接运行。


例子


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JFrameSimpleDemo extends JFrame{
    String sizes[]={"100*100","200*200","300*300", "400*400", "500*500"};
    JComboBox cboSize        =new JComboBox(sizes);
    JRadioButton colorRed    =new JRadioButton("红色");//红色 绿色 蓝色 黄色
    JRadioButton colorGreen  =new JRadioButton("绿色");
    JRadioButton colorBlue   =new JRadioButton("蓝色");
    JRadioButton colorYellow =new JRadioButton("黄色");
    
    public JFrameSimpleDemo(){
        super("JFrameSimpleDemo");
        setLayout(new FlowLayout());
        setSize(300,300);
        this.add(cboSize);
        this.add(colorRed);
        this.add(colorGreen);
        this.add(colorBlue);
        this.add(colorYellow);
        ButtonGroup bg = new ButtonGroup();
        bg.add(colorRed);
        bg.add(colorGreen);
        bg.add(colorBlue);
        bg.add(colorYellow);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        setVisible(true);
        cboSize.addItemListener(new ItemListener(){
            public void itemStateChanged(ItemEvent e){
                if(e.getStateChange()==ItemEvent.SELECTED){
                    String ss[]=((String)e.getItem()).split("\\*");
                    int w=Integer.parseInt(ss[0]);
                    int h=Integer.parseInt(ss[1]);
                    JFrameSimpleDemo.this.setSize(w, h);
                }
            }
        }) ;
        
        ActionListener chl=new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if(colorRed.equals(e.getSource())){
                    JFrameSimpleDemo.this.getContentPane().setBackground(Color.red);
                    
                }else if(colorGreen.equals(e.getSource())){
                    JFrameSimpleDemo.this.getContentPane().setBackground(Color.green);
                    
                }else if(colorBlue.equals(e.getSource())){
                    JFrameSimpleDemo.this.getContentPane().setBackground(Color.blue);
                    
                }else if(colorYellow.equals(e.getSource())){
                    JFrameSimpleDemo.this.getContentPane().setBackground(Color.yellow);
                }
            }
        };
        
        colorRed.addActionListener(chl);
        colorGreen.addActionListener(chl);
        colorBlue.addActionListener(chl);
        colorYellow.addActionListener(chl);
    }
    public static void  main(String[] args){
        new JFrameSimpleDemo();
    }    
}

回答2:

估计是注册的用户权限不足,要用专业版的注册码注册才行,下面是8.5/8.6的注册码,重新注册下就有了,其他版本楼主自己搜索吧
zhuce
mLR8ZC-655909-69587657677565032

admin
nLR8ZC-655881-6958765271456420

回答3:

new ---> other ---> windowBuilder --> Swing 或者 Jframe