80 lines
2.4 KiB
Java
80 lines
2.4 KiB
Java
package de.ctdo.crashtest.cardplayer;
|
|
|
|
import de.ctdo.crashtest.cardplayer.irc.*;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
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");
|
|
setPreferredSize(new Dimension(600,500));
|
|
irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "irc.ctdo.de", 6667);
|
|
|
|
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);
|
|
if(irc != null) irc.say("crashtest: wall " + item);
|
|
}
|
|
}
|
|
});
|
|
|
|
JScrollPane listScroller = new JScrollPane(jList);
|
|
listScroller.setPreferredSize(new Dimension(600, 500));
|
|
|
|
add(listScroller);
|
|
pack();
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
}
|