Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2016
    Posts
    2
    Rep Power
    0

    Default Something went terribly wrong

    I was playing around, trying to do random stuff, and I came across a problem. Could you please look at my code? I'm new to java xD
    package me.Ryder.Test;

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Color;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;

    public class Main extends JFrame implements ActionListener{


    private static final long serialVersionUID = 1L;


    String userWord = "";
    String playerUsername = "";
    JTextField userInput;
    JTextField usernameInput;
    JTextField chatBox;


    public Main() {
    JFrame jf = new JFrame();
    JPanel panel = new JPanel();
    JButton submitButton = new JButton("Send message");
    JButton usernameButton = new JButton("Create Username");
    userInput = new JTextField("", 20);
    usernameInput = new JTextField("", 20);
    usernameInput.setEditable(true);
    submitButton.addActionListener( (e) -> {
    submitAction();

    usernameButton.addActionListener( (i) -> {
    usernameAction();
    });
    jf.setSize(500, 500);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.add(panel);
    panel.add(userInput);
    panel.add(usernameInput);
    panel.add(submitButton);
    panel.add(usernameButton);




    }

    public void actionPerformed(ActionEvent e) {}

    private void usernameAction() {
    playerUsername = usernameInput.getText();




    }
    private void submitAction() {
    userWord = userInput.getText();
    Color blueColor = Color.blue;
    Color redColor = Color.red;
    String textChat = blueColor + playerUsername + ": " + redColor + userWord;

    }

    public static void main(String[] args) {
    new Main();
    }}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Something went terribly wrong

    I came across a problem
    Please explain.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Nov 2016
    Posts
    2
    Rep Power
    0

    Default Re: Something went terribly wrong

    Sorry, I'm new to the forums. The problem is that it says Syntax error, insert ";" to complete Statement, but I don't see anywhere I've made a mistake. My code can be found here:
    Java Code:
    package me.Ryder.Test;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Color;
    import java.awt.Component;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class Main extends JFrame implements ActionListener{
    
    
    	private static final long serialVersionUID = 1L;
    	
    
    String userWord = "";
    String playerUsername = "";
    String userChat = "";
    String textChat = "";
    JTextField userInput;
    JTextField usernameInput;
    JTextField chatBox;
    JTextField getText;
    
    
    public Main()  {
        JFrame jf = new JFrame();
        JPanel panel = new JPanel();
        JButton submitButton = new JButton("Send message");
        JButton usernameButton = new JButton("Create Username");
        userInput = new JTextField("", 20);
        getText = new JTextField("", 20);
        usernameInput = new JTextField("", 20);
        usernameInput.setEditable(true);
        submitButton.addActionListener( (e) -> {
            submitAction();
        
        usernameButton.addActionListener( (e) -> {
            usernameAction();
       });
        jf.setSize(500, 500);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.add(panel);
        panel.add(userInput);
        panel.add(usernameInput);
        panel.add(submitButton);
        panel.add(usernameButton);
    The complete set of errors:
    Lambda expression's parameter e cannot redeclare another local variable defined in an enclosing scope. Java Problem
    Syntax error, insert ";" to complete Statement
    Syntax error, insert ")" to complete Expression
    Syntax error, insert "}" to complete Block
    The method getText() is undefined for the type String
    Last edited by ChessIndustries; 11-19-2016 at 03:28 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Something went terribly wrong

    it says Syntax error, insert ";" to complete Statement,
    Can you copy the full contents of the compiler's error messages and paste it here. It should show the source lines where the errors happened.

    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    My code can be found here:
    The end of the source code is missing.
    Last edited by Norm; 11-19-2016 at 03:52 AM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    6

    Default Re: Something went terribly wrong

    'Looks like line 40 was deleted by accident. It should look like line 43.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 10:28 PM
  3. Replies: 10
    Last Post: 07-16-2010, 01:34 AM
  4. What am I doing wrong??
    By NoNickName in forum New To Java
    Replies: 3
    Last Post: 04-24-2009, 12:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •