78 lines
2.2 KiB
Java
78 lines
2.2 KiB
Java
package de.ctdo.crashtest.cardplayer;
|
|
|
|
import de.ctdo.crashtest.cardplayer.irc.*;
|
|
import javax.swing.*;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.io.*;
|
|
import java.util.Vector;
|
|
|
|
public class MainFrame extends JFrame {
|
|
private IrcClient irc;
|
|
private JList<String> jList;
|
|
|
|
public MainFrame() {
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
setTitle("CrastestCardPlayer");
|
|
setBounds(100, 100, 600, 400);
|
|
|
|
irc = new IrcClient(HostHelper.getHostName(), "#crashtest", "irc.ctdo.de");
|
|
|
|
initGui();
|
|
|
|
setVisible(true);
|
|
}
|
|
|
|
private void initGui() {
|
|
jList = new JList<String>(readData());
|
|
jList.setLayoutOrientation(JList.VERTICAL);
|
|
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
|
|
jList.addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
if(e.getClickCount() == 2){
|
|
int index = jList.locationToIndex(e.getPoint());
|
|
ListModel dlm = jList.getModel();
|
|
Object item = dlm.getElementAt(index);
|
|
jList.ensureIndexIsVisible(index);
|
|
System.out.println("Double clicked on " + item);
|
|
irc.say("crashtest: wall " + item);
|
|
}
|
|
}
|
|
});
|
|
|
|
add(jList);
|
|
}
|
|
|
|
|
|
private Vector<String> readData() {
|
|
try {
|
|
File file;
|
|
BufferedReader br;
|
|
|
|
file = new File ("messages.txt");
|
|
if(file.exists()) {
|
|
br = new BufferedReader(new FileReader (file));
|
|
} else {
|
|
InputStream is = Main.class.getResourceAsStream("/messages.txt");
|
|
br = new BufferedReader(new InputStreamReader(is));
|
|
}
|
|
|
|
Vector<String> lines = new Vector<String>();
|
|
String line;
|
|
while((line=br.readLine())!=null) {
|
|
lines.add(line);
|
|
}
|
|
|
|
return lines;
|
|
} catch(Exception e) {
|
|
e.printStackTrace();
|
|
Vector<String> vector = new Vector<String>();
|
|
vector.add("could not read the input file...");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|