Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java unknown error #454

Open
NeroMn-ExE opened this issue May 11, 2024 · 0 comments
Open

Java unknown error #454

NeroMn-ExE opened this issue May 11, 2024 · 0 comments

Comments

@NeroMn-ExE
Copy link

Hello i got some issue with it
i been start coding for 3 months and im using BlueJ
im trying to write simple online bank code with a login,registering and saving there datas with it.
this is my code( i got help from chatgpt for adding interface function):

import javax.swing.;
import java.awt.
;
import java.awt.event.;
import java.io.
;
import java.util.Scanner;

public class Burtgel extends JFrame implements ActionListener {
public static final String USER_FILENAME = "Hereglegch.ser";
public static final String ACCOUNT_FILENAME = "Account.ser";
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 200;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private JButton cancelButton;
private JButton okButton;
private JTextField inputLine;
private JLabel prompt;

public Burtgel() {
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());

    prompt = new JLabel("Нэр: "); // Initializing prompt with a default text
    contentPane.add(prompt);

    inputLine = new JTextField(20);
    contentPane.add(inputLine);
    inputLine.addActionListener(this);

    okButton = new JButton("OK");
    contentPane.add(okButton);
    cancelButton = new JButton("CANCEL");
    contentPane.add(cancelButton);

    cancelButton.addActionListener(this);
    okButton.addActionListener(this);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == cancelButton) {
        // Handle cancel button click
        // For example, close the window
        dispose();
    } else if (e.getSource() == okButton || e.getSource() == inputLine) {
        // Handle OK button click or Enter key press in the input field
        String userInput = inputLine.getText();
        // Process the user input further
    }
}

public static void main(String[] args) {
    // Assuming you want to call either login or register based on some condition
    // Replace the condition with your logic
    boolean isLoggedIn = false; // Set it to true if the user is already logged in
    if (isLoggedIn) {
        login();
    } else {
        register();
    }
}

public static void register() {
    try (Scanner scanner = new Scanner(System.in)) {
        JFrame frame = new Burtgel();
        frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
        frame.setResizable(false);
        frame.setTitle("Registration");
        frame.setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
        frame.setVisible(true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public static void login() {
try (Scanner scanner = new Scanner(System.in);
FileInputStream userFileIn = new FileInputStream(USER_FILENAME);
ObjectInputStream userIn = new ObjectInputStream(userFileIn);
FileInputStream haygFileIn = new FileInputStream(ACCOUNT_FILENAME);
ObjectInputStream haygIn = new ObjectInputStream(haygFileIn)) {

    JFrame frame = new Burtgel();
    frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    frame.setResizable(false);
    frame.setTitle("Login");
    frame.setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());

    JLabel prompt = new JLabel("Нэр: ");
    contentPane.add(prompt);

    Hereglegch user = (Hereglegch) userIn.readObject();
    Account hayg = (Account) haygIn.readObject();

    String username = scanner.nextLine();

    if (!user.getName().equals(username)) {
        prompt.setText("Хэрэглэгч олдсонгүй.");
        return;
    }

    JLabel prompt2 = new JLabel("Нууц үг: ");
    contentPane.add(prompt2);
    String password = scanner.nextLine();

    if (!user.getPassword().equals(password)) {
        prompt.setText("Нууц үг буруу байна.");
        return;
    }

    prompt.setText("Амжилттай нэвтэрлээ");
    Balance balance = new Balance(hayg);
    frame.setVisible(true);
    Undsen.displayInfo(hayg, balance);

} catch (IOException | ClassNotFoundException ex) {
    ex.printStackTrace();
}

}
}

oftenly my coding programm shows me where i got wronged but this time it says:
Error(s) found in class. Press Ctrl+K or click right to go to next error.
And doesnt show me where i got mistake, i have no idea about where i lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant