[Source Code] RSPS Simple Cmd Gen
Just decided to post this old source i had laying around for a command generator i made in java, it is pretty basic and should be easy to add onto
and make it more advanced.
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class CommandGenerator extends JFrame{
JButton button;
JLabel cmdl, iteml, amountl, sourcel;
JTextField cmd, item, amount, message;
JTextArea source;
int x;
int y;
public CommandGenerator(int x, int y){
this.x = x;
this.y = y;
getContentPane().setLayout(null);
setGUI();
getContentPane().setLayout(null);
}
public void setGUI(){
//text fields
cmd = new JTextField();
cmd.setSize(200, 25);
cmd.setLocation(0, 25);
getContentPane().add(cmd);
//next
item = new JTextField();
item.setSize(100, 25);
item.setLocation(0, 75);
getContentPane().add(item);
//next
amount = new JTextField();
amount.setSize(100, 25);
amount.setLocation(200, 75);
getContentPane().add(amount);
//textarea
source = new JTextArea();
source.setSize(400, 200);
source.setLocation(0, 125);
getContentPane().add(source);
//labels
cmdl = new JLabel("Command:");
cmdl.setSize(100, 25);
cmdl.setLocation(0, 0);
getContentPane().add(cmdl);
//next
iteml = new JLabel("Item:");
iteml.setSize(100, 25);
iteml.setLocation(0, 50);
getContentPane().add(iteml);
//next
amountl = new JLabel("Amount:");
amountl.setSize(100, 25);
amountl.setLocation(200, 50);
getContentPane().add(amountl);
//next
sourcel = new JLabel("Source:");
sourcel.setSize(100, 25);
sourcel.setLocation(0, 100);
getContentPane().add(sourcel);
//button
button = new JButton();
button.setText("Generate");
button.setSize(100, 50);
button.setLocation(5, 350);
getContentPane().add(button);
//frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Command Generator");
setSize(x, y);
setResizable(false);
setVisible(true);
//action listeners
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
source.append("if(cmd[0].equals(\"" + cmd.getText() + "\"){ \n");
source.append(" " + "if(player.getRights() == 1){ \n");
source.append(" " + "player.getInvetory().addItem(" + item.getText() + ", " + amount.getText() + "); \n");
source.append(" " + "player.sm(\"[SERVER] Player received item:" + item.getText() + "\"); \n");
source.append(" " + "} \n");
source.append("}");
}
});
}
public static void main(String[] args){
CommandGenerator gen = new CommandGenerator(400, 450);
}
}