#自学java的卑微打工人#

img


使用eclipse设计窗口界面,但显示导入import和JFrame都是错误,是什么原因呢?

你添加JFrame这个组件了么?import那几行该不会是你手敲上去的吧???

检查项目的构建路径:首先确保项目的构建路径中包含了正确的类库。在Eclipse中,可以通过右键单击项目,选择"Properties",然后在"Java Build Path"选项卡下查看是否有缺失的类库。如果有缺失的类库,可以点击"Add Library"按钮来添加。

检查JDK版本:确保项目使用的是正确的JDK版本。在Eclipse中,可以通过右键单击项目,选择"Properties",然后在"Java Compiler"选项卡下设置合适的JDK版本。

检查导入语句:确保导入语句正确无误。在Eclipse中,可以使用快捷键"Ctrl+Shift+O"来自动导入所需的类。

【相关推荐】



  • 请看👉 :eclipse编程过程中JFrame报错
  • 除此之外, 这篇博客: 使用eclipse设计学生管理系统中的 9.完善mainframe.java 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    1)定义元素

    public class mainframe extends JFrame {
    
    	private JPanel contentPane;
    	public static usertype usertype;
    	public static Object userobject;
    	private JDesktopPane desktopPane;
    ...

    2)注销原有的样式

    //	public static void main(String[] args) {
    //		EventQueue.invokeLater(new Runnable() {
    //			public void run() {
    //				try {
    //					mainframe frame = new mainframe();
    //					frame.setVisible(true);
    //				} catch (Exception e) {
    //					e.printStackTrace();
    //				}
    //			}
    //		});
    //	}

    3)

    public mainframe(usertype usertype,Object userObject) {
    		this.usertype=usertype;
    		this.userobject=userObject;
    		...
    		setLocationRelativeTo(null);
    ....

    4)给修改密码添加一个监听事件

    menuItem.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				editpassword(ae);
    			}
    		});

    5)给退出系统添加一个监听事件

    menuItem_1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if(JOptionPane.showConfirmDialog(mainframe.this, "确定要退出吗?")==JOptionPane.OK_OPTION){
    					System.exit(0);
    				}
    			}
    		});

    6)给添加班级添加一个监听事件

    menuItem_2.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    //				//addclassframe addclassframe=new addclassframe();
    //				addclassframe.setVisible(true);
    //				desktopPane.add(addclassframe);
    			}
    		});

    7)定义 editpassword

    protected void editpassword(ActionEvent ae) {
    		// TODO Auto-generated method stub
    		editpasswordframe editpasswordframe = new editpasswordframe();
    		editpasswordframe.setVisible(true);
    		desktopPane.add(editpasswordframe);
    	}

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^