added a option to set game states from this window

This commit is contained in:
Lucas Pleß 2012-06-15 10:00:41 +02:00
parent 9170d4b024
commit 96e3dfd955
1 changed files with 51 additions and 14 deletions

View File

@ -10,40 +10,77 @@ import java.util.Vector;
public class MainFrame extends JFrame {
private IrcClient irc;
private JList<String> jList;
private JList<String> jListWall;
private JList<String> jListStates;
public MainFrame() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("CrastestCardPlayer");
setPreferredSize(new Dimension(600,500));
irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "irc.ctdo.de", 6667);
setPreferredSize(new Dimension(800,500));
irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "localhost", 8888);
initGui();
setVisible(true);
}
private void initGui() {
jList = new JList<String>(readData());
jList.setLayoutOrientation(JList.VERTICAL);
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Container contentPane = this.getContentPane();
jList.addMouseListener(new MouseAdapter() {
jListWall = new JList<String>(readData());
jListWall.setLayoutOrientation(JList.VERTICAL);
jListWall.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jListWall.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = jList.locationToIndex(e.getPoint());
ListModel dlm = jList.getModel();
int index = jListWall.locationToIndex(e.getPoint());
ListModel dlm = jListWall.getModel();
Object item = dlm.getElementAt(index);
jList.ensureIndexIsVisible(index);
if(irc != null) irc.say("crashtest: wall " + item);
jListWall.ensureIndexIsVisible(index);
if (irc != null) irc.say(">wall " + item);
}
}
});
JScrollPane listScroller = new JScrollPane(jList);
JScrollPane listScroller = new JScrollPane(jListWall);
listScroller.setPreferredSize(new Dimension(600, 500));
add(listScroller);
contentPane.setLayout(new BorderLayout());
contentPane.add(listScroller, BorderLayout.WEST);
Vector<String> states = new Vector<String>();
states.add("IDLE");
states.add("ENTERED_ROOM");
states.add("TABLE_GAME_ONE");
states.add("TABLE_GAME_TWO");
states.add("TABLE_GAME_THREE");
states.add("TABLE_GAME_FOUR");
states.add("TABLE_GAME_FIVE");
states.add("TABLE_GAME_SIX");
states.add("TABLE_GAME_DONE");
states.add("ROKET_STARTED");
states.add("ROKET_DONE");
states.add("NEUTRAL");
jListStates = new JList<String>(states);
jListStates.setLayoutOrientation(JList.VERTICAL);
jListStates.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jListStates.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = jListStates.locationToIndex(e.getPoint());
ListModel dlm = jListStates.getModel();
Object item = dlm.getElementAt(index);
jListStates.ensureIndexIsVisible(index);
if (irc != null) irc.say(">state " + item);
}
}
});
listScroller = new JScrollPane(jListStates);
contentPane.add(listScroller);
pack();
}