weixin_57403445 2021-12-22 19:45 采纳率: 0%
浏览 37

Java编译出错问题

cannot be resolved to a type 是什么原因?

img

亮红灯的都是这种问题

package edu.lj.gui;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Menu;

public class Longin {

    private static Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="256,9"
    private Label label_01 = null;
    private Label label_02 = null;
    private Text text_01 = null;  //  @jve:decl-index=0:
    private Text text_02 = null;  //  @jve:decl-index=0:visual-constraint="909,145"
    private Label label_03 = null;
    private Button button_01 = null;
    private Button button_02 = null;

    public static void main(String[] args) {
        Display display = Display.getDefault();
        Longin thisClass = new Longin();
        thisClass.createSShell();
        thisClass.sShell.open();         //打开登录面板
        
        sShell.setSize(650, 400);
        sShell.setLocation(Display.getCurrent().getClientArea().width / 2 - sShell.getShell().getSize().x/2,
                Display.getCurrent().getClientArea().height / 2- sShell.getSize().y/2);  //使屏幕居中

        

        while (!thisClass.sShell.isDisposed()) {
            if (!display.readAndDispatch())    //如果登录失败,不消除界面
                display.sleep();
        }
        display.dispose();        //清除这个界面
    }

    private void createSShell() {
        sShell = new Shell();
        sShell.setText("登录");
        sShell.setSize(new Point(669, 375));
        sShell.setLayout(null);
        label_01 = new Label(sShell, SWT.NONE);
        label_01.setBounds(new Rectangle(144, 134, 61, 32));
        label_01.setFont(new Font(Display.getDefault(), "Microsoft YaHei UI", 12, SWT.NORMAL));
        label_01.setText("账号:");
        label_02 = new Label(sShell, SWT.NONE);
        label_02.setBounds(new Rectangle(142, 185, 61, 32));
        label_02.setFont(new Font(Display.getDefault(), "Microsoft YaHei UI", 12, SWT.NORMAL));
        label_02.setText("密码:");
        text_01 = new Text(sShell, SWT.BORDER);
        text_01.setBounds(new Rectangle(248, 135, 217, 32));
        text_02 = new Text(sShell, SWT.BORDER | SWT.PASSWORD);
        text_02.setBounds(new Rectangle(249, 187, 218, 34));
        text_02.setEchoChar('*');
        label_03 = new Label(sShell, SWT.NONE);
        label_03.setBounds(new Rectangle(222, 57, 183, 48));
        label_03.setFont(new Font(Display.getDefault(), "Microsoft YaHei UI", 15, SWT.NORMAL));
        label_03.setText("面试打分系统");
        button_01 = new Button(sShell, SWT.NONE);
        button_01.setBounds(new Rectangle(171, 249, 73, 43));
        button_01.setFont(new Font(Display.getDefault(), "Microsoft YaHei UI", 12, SWT.NORMAL));
        button_01.setText("登录");
        button_01.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                
                try{  
                     //定义数据库联接的驱动程序
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
                     //定义数据库的联接地址
                    String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D://0000//Dat//Dat1.mdb"; //JDBC ,//String url="jdbc:odbc:redsun"; //ODBC
                    //    String url = "jdbc:odbc:Dat";
                    //使用DriverManager类的getConnection()方法建立联接
                    Connection con=DriverManager.getConnection(url,"","");
                    //利用连接con的方法创建Statement对象,以便执行SQL查询
                    
                    Statement stmt=con.createStatement();        
                    String sql="Select * from Account"; 
                    System.out.println(sql);
                    ResultSet rs=stmt.executeQuery(sql); 
                    
                    int flag = -1;    //对输入的账号和密码进行判断
                    while(rs.next()){
                        if(text_01.getText().trim().equals(rs.getString("acount")) && 
                            text_02.getText().trim().equals(rs.getString("password"))){
                            
                            Menu01 m = new Menu01();
                             m.createSShell();
                             m.sShell.open();
                            sShell.setVisible(false);
                            flag = 1;
                            break;
                        }
                    }
                    if(flag == -1){
                        MessageBox ms=new MessageBox(sShell);
                           ms.setMessage("账号或密码错误!");
                           ms.open();
                    }
                    stmt.close();
                    con.close();  
                }
                catch(Exception e1){
                    e1.printStackTrace();    //捕获异常
                }
                
            }
        });
        button_02 = new Button(sShell, SWT.NONE);
        button_02.setBounds(new Rectangle(333, 249, 72, 44));
        button_02.setFont(new Font(Display.getDefault(), "Microsoft YaHei UI", 12, SWT.NORMAL));
        button_02.setText("取消");
        button_02.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                    System.exit(0);  
            }
        });
    }

}


  • 写回答

1条回答 默认 最新

  • QTT_csdn 2021-12-22 20:02
    关注

    看一下jdk配置

    评论

报告相同问题?

问题事件

  • 创建了问题 12月22日

悬赏问题

  • ¥15 更换了一个新的win10系统,再下载VS时碰到的问题,是C++组件的?
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线
  • ¥20 无法创建新的堆栈防护界面
  • ¥15 sessionStorage在vue中的用法
  • ¥15 wordpress更换域名后用户图片头像不显示
  • ¥15 如何在ubunto上安装CEF (Chromium Embedded Framework),并且基于qt实现打开一个web
  • ¥30 AD9854 为什么输出波形幅度受限,AI机器人勿扰
  • ¥15 如何在ubunto上安装CEF (Chromium Embedded Framework