JDBC 產生(JAVAC) .' expected

1 import java.sql.*;

2. import java.awt.*;

3 .import java.awt.event.*;

4. import javax.swing.*;

5 .import MyWindowListener; // 在相同目錄

public class AuthMain extends JFrame

{

}

Error Message: //

AuthMain.java 6:'.' expected

import MyWindowListener

AuthMain.java 6:';' expected

import MyWindowListener

/************** MyWindowListener.java *************/

import java.awt.*;

import java.awt.event.*;

public class MyWindowListener extends WindowAdapter

{

public void windowClosing(WindowEvent e)

{

System.exit(1);

}

}

3 Answers

Rating
  • John
    Lv 7
    6 years ago
    Best Answer

    嘅然在同一個folder又何必import呢?妳係唔係想咁呀?

    import java.awt.event.WindowAdapter;

    import java.awt.event.WindowEvent;

    import javax.swing.JFrame;

    import javax.swing.JLabel;

    import javax.swing.JOptionPane;

    import javax.swing.JPanel;

    import javax.swing.JTextField;

    import javax.swing.WindowConstants;

    public class Program {

    public static void main(String[] args) {

    AuthMain authMain = new AuthMain();

    authMain.setVisible(true);

    }

    }

    public class AuthMain extends JFrame {

    private static final long serialVersionUID = 4055467376016475744L;

    private JTextField txtUsername;

    public AuthMain() {

    initialise();

    }

    private void initialise() {

    JPanel pane = new JPanel();

    pane.add(new JLabel("Username: "));

    txtUsername = new JTextField(15);

    pane.add(txtUsername);

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    addWindowListener(new MyWindowListener());

    getContentPane().add(pane);

    setTitle("Login");

    setVisible(false);

    setSize(300, 300);

    }

    }

    public class MyWindowListener extends WindowAdapter {

    @Override

    public void windowClosing(WindowEvent e) {

    final String message = "Are you sure you want to quit?";

    final String title = "Confirm exit.";

    final int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.OK_CANCEL_OPTION);

    if (JOptionPane.OK_OPTION == result) {

    System.exit(0);

    }

    }

    @Override

    public void windowOpened(WindowEvent e) {

    }

    @Override

    public void windowClosed(WindowEvent e) {

    }

    @Override

    public void windowIconified(WindowEvent e) {

    }

    @Override

    public void windowDeiconified(WindowEvent e) {

    }

    @Override

    public void windowActivated(WindowEvent e) {

    }

    @Override

    public void windowDeactivated(WindowEvent e) {

    }

    }

  • 6 years ago

    參考下面的網址看看

    http://phi008780520.pixnet.net/blog

  • 6 years ago

    已經了解同目錄無需 import,謝謝

Still have questions? Get your answers by asking now.