0
.\Bulby\Gui.java:118: error: cannot find symbol
    pl.getActionSender().sendMessage(pl, "<col=336600>[Server Message] " + text);
    ^
    symbol:   method getActionSender()
    location: variable pl of type Player
    Note: .\Bulby\players\objectLoader.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: .\Bulby\clanchat\Room.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    Press any key to continue . . .














    /*

* 类 Gui * * 版本 1.0 * * 2013 年 10 月 31 日星期四 * * 由 Dragnnight 创建 */

package Bulby;
import Bulby.Server;
import Bulby.Engine;
import Bulby.players.Player;
import Bulby.util.Misc;
import Bulby.*;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Gui extends JFrame {

static private JTextField textkick;
private JLabel textt;
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JPanel panel;

public Gui() {
super("Your servers name goes here thank xx pkpure xx - Control Panel"); // The title bar
setLayout(new FlowLayout()); // This is the layout of the Gui
JPanel panel = new JPanel(new GridBagLayout());

/**textt = new JLabel("Enter a name to kick.");                
textkick = new JTextField("Enter a username to kick");
textkick.setToolTipText("Type in the username to kick here.");
**/

button1 = new JButton("Kick"); //button on the gui
button1.setToolTipText("Kick a player."); //Hover text
            button1.setActionCommand("kick");

            button2 = new JButton("Get players count"); //button on the gui
            button2.setToolTipText("Get players count."); //Hover text
            button2.setActionCommand("gplayers");

            button3 = new JButton("Get players names"); //button on the gui
            button3.setToolTipText("Get players names."); //Hover text
            button3.setActionCommand("gnplayers");

            button4 = new JButton("Masstext"); //button on the gui
            button4.setToolTipText("Send a masstext."); //Hover text
            button4.setActionCommand("masstext");

            add(panel);

            GridBagConstraints c = new GridBagConstraints();
            /**
            c.gridx = 0; //Position of textt
            c.gridy = 0; // All of these are the X, Y position of the selected item
            panel.add(textt); //For example, here the selected item is "textt"
            c.gridx = 50;
            c.gridy = 5;
            panel.add(textkick);        
            c.gridx = 100;
            c.gridy = 10;
            **/ 
            panel.add(button1);
            panel.add(button2);
            panel.add(button3);
            panel.add(button4);

            button1.addActionListener(new Action()); //Adds an ActionListener to button1
            button2.addActionListener(new Action()); //Adds an ActionListener to button2
            button3.addActionListener(new Action()); //Adds an ActionListener to button3
            button4.addActionListener(new Action()); //Adds an ActionListener to button4
    }

    static class Action implements ActionListener {
       public void actionPerformed (ActionEvent e) {



        if ("kick".equals(e.getActionCommand())) {
        String kickwho=JOptionPane.showInputDialog(null, "Username to kick");
            Player p2 = Server.engine.players[Engine.getIdFromName(kickwho)];
            System.out.println("[GUI] Kicked "+kickwho+" from the server."); //What happens when button1 is clicked
            }

            if ("gplayers".equals(e.getActionCommand())) {
            JOptionPane.showMessageDialog(null, Server.engine.getPlayerCount());
            }

            if("gnplayers".equals(e.getActionCommand())){
            String names = "";
                            for (Player pl : Server.engine.players) {
                                            if (pl != null) {
                                                    names = names + pl.username + ", ";
                                            }
                            }
            JOptionPane.showMessageDialog(null, names);
            }

            if("masstext".equals(e.getActionCommand())){
            String text=JOptionPane.showInputDialog(null, "Text:");
            int sent2 = 0;
                            for (Player pl : Server.engine.players) {
                                            if (pl != null) {

pl.getActionSender().sendMessage(pl, "<col=336600>[Server Message] " + text);

                                                    sent2++;

                                            }
                            }
            JOptionPane.showMessageDialog(null, "Mass message sent to " + sent2 + " players.");
            }



                    }
            } 
    }

我只需要一些帮助来确定如何在代码中定义 Pl,因为在它上面我确实定义了它但它没有接受而且我不确定为什么或者我没有正确定义它或其他什么

4

1 回答 1

0

该错误表明Player该类(Bulby.players.Player我相信是您自己的类)不包含具有签名的方法getActionSender()

检查该方法是否存在,然后检查它是否具有与上述相同的签名(即,没有参数)。

于 2013-11-03T08:03:35.673 回答