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 { public class MainFrame extends JFrame {
private IrcClient irc; private IrcClient irc;
private JList<String> jList; private JList<String> jListWall;
private JList<String> jListStates;
public MainFrame() { public MainFrame() {
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("CrastestCardPlayer"); setTitle("CrastestCardPlayer");
setPreferredSize(new Dimension(600,500)); setPreferredSize(new Dimension(800,500));
irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "irc.ctdo.de", 6667); irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "localhost", 8888);
initGui(); initGui();
setVisible(true); setVisible(true);
} }
private void initGui() { private void initGui() {
jList = new JList<String>(readData()); Container contentPane = this.getContentPane();
jList.setLayoutOrientation(JList.VERTICAL);
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jList.addMouseListener(new MouseAdapter() { jListWall = new JList<String>(readData());
jListWall.setLayoutOrientation(JList.VERTICAL);
jListWall.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jListWall.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){ if (e.getClickCount() == 2) {
int index = jList.locationToIndex(e.getPoint()); int index = jListWall.locationToIndex(e.getPoint());
ListModel dlm = jList.getModel(); ListModel dlm = jListWall.getModel();
Object item = dlm.getElementAt(index); Object item = dlm.getElementAt(index);
jList.ensureIndexIsVisible(index); jListWall.ensureIndexIsVisible(index);
if(irc != null) irc.say("crashtest: wall " + item); if (irc != null) irc.say(">wall " + item);
} }
} }
}); });
JScrollPane listScroller = new JScrollPane(jList); JScrollPane listScroller = new JScrollPane(jListWall);
listScroller.setPreferredSize(new Dimension(600, 500)); 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(); pack();
} }