radical chat clean up, see forum for details
This commit is contained in:
@@ -1,177 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MainFrameGui
|
||||
extends Frame
|
||||
{
|
||||
public static TextArea messages;
|
||||
public static TextField eingabe;
|
||||
public static List userliste;
|
||||
public static Checkbox cb;
|
||||
public static Button hilfebutton;
|
||||
public static GridBagConstraints makegbc;
|
||||
public static TextDialog hilfedialog;
|
||||
public static MenuBar menu;
|
||||
|
||||
public MainFrameGui()
|
||||
{
|
||||
super ("ARSC Really Simple Chat");
|
||||
setBackground(Color.lightGray);
|
||||
addWindowListener(new WindowClosingAdapter(true));
|
||||
|
||||
//Menü
|
||||
MenuBar menu = new MenuBar();
|
||||
Menu menuConnection = new Menu("Connection");
|
||||
menuConnection.add("Connect to server");
|
||||
menuConnection.add("Disconnect from server");
|
||||
menuConnection.add("Quit");
|
||||
Menu menuConfiguration = new Menu("Configuration");
|
||||
Menu menuHelp = new Menu("Help");
|
||||
MenuItem mi = new MenuItem("Show commands");
|
||||
mi.addActionListener(new hilfebuttonListener());
|
||||
menuHelp.add(mi);
|
||||
menuHelp.add("About...");
|
||||
menu.add(menuConnection);
|
||||
menu.add(menuConfiguration);
|
||||
menu.add(menuHelp);
|
||||
|
||||
setMenuBar(menu);
|
||||
|
||||
//Layout setzen und Komponenten hinzufügen
|
||||
GridBagLayout gbl = new GridBagLayout();
|
||||
GridBagConstraints gbc;
|
||||
setLayout(gbl);
|
||||
|
||||
//TextArea hinzufügen
|
||||
messages = new TextArea("", 20, 20, TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
gbc = makegbc(0, 0, 2, 2);
|
||||
gbc.weightx = 100;
|
||||
gbc.weighty = 100;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbl.setConstraints(messages, gbc);
|
||||
add(messages);
|
||||
|
||||
//Userliste
|
||||
userliste = new List();
|
||||
userliste.add("pgod");
|
||||
userliste.add("HanSolo");
|
||||
userliste.add("dArUdE");
|
||||
gbc = makegbc(2, 0, 2, 2);
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbl.setConstraints(userliste, gbc);
|
||||
userliste.addActionListener(new userlisteListener());
|
||||
add(userliste);
|
||||
|
||||
//Eingabefeld
|
||||
eingabe = new TextField();
|
||||
gbc = makegbc(0, 2, 1, 1);
|
||||
gbc.weightx = 100;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.SOUTH;
|
||||
gbl.setConstraints(eingabe, gbc);
|
||||
eingabe.addActionListener(new eingabeListener());
|
||||
add(eingabe);
|
||||
|
||||
//Checkbox
|
||||
cb = new Checkbox("Scrolling");
|
||||
cb.setState(true);
|
||||
gbc = makegbc(1, 2, 1, 1);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.SOUTH;
|
||||
gbl.setConstraints(cb, gbc);
|
||||
add(cb);
|
||||
|
||||
//Hilfebutton
|
||||
hilfebutton = new Button("Help");
|
||||
gbc = makegbc(2, 2, 1, 1);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbl.setConstraints(hilfebutton, gbc);
|
||||
hilfebutton.addActionListener(new hilfebuttonListener());
|
||||
add(hilfebutton);
|
||||
//Gib ihm
|
||||
pack();
|
||||
hilfedialog = new TextDialog(this, "Hilfe", "Hilfe\nLala\nLulu...", "Schliessen", false, 200, 400);
|
||||
}
|
||||
|
||||
//Die Listener
|
||||
public class eingabeListener
|
||||
implements ActionListener
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
System.out.println("Event erhalten");
|
||||
TextField source = (TextField)event.getSource();
|
||||
messages.append("\n" + source.getText());
|
||||
source.selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
public class userlisteListener
|
||||
implements ActionListener
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
System.out.println("userliste Event erhalten");
|
||||
List source = (List)event.getSource();
|
||||
eingabe.setText("/msg " + source.getSelectedItem() + " ");
|
||||
eingabe.setCaretPosition(99);
|
||||
eingabe.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
public class hilfebuttonListener
|
||||
implements ActionListener
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
System.out.println("hilfebutton Event erhalten");
|
||||
if(getToolkit().getScreenSize().width - (getBounds().x + getBounds().width) >= hilfedialog.getSize().width)
|
||||
{
|
||||
hilfedialog.setLocation(getBounds().x + getBounds().width, getBounds().y);
|
||||
}
|
||||
else
|
||||
{
|
||||
hilfedialog.setLocation(getToolkit().getScreenSize().width - hilfedialog.getSize().width, getBounds().y);
|
||||
}
|
||||
hilfedialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowClosingAdapter
|
||||
extends WindowAdapter
|
||||
{
|
||||
private boolean exitSystem;
|
||||
|
||||
public WindowClosingAdapter(boolean exitSystem)
|
||||
{
|
||||
this.exitSystem = exitSystem;
|
||||
}
|
||||
|
||||
public WindowClosingAdapter()
|
||||
{
|
||||
this(true);
|
||||
}
|
||||
|
||||
public void windowClosing(WindowEvent event)
|
||||
{
|
||||
event.getWindow().setVisible(false);
|
||||
event.getWindow().dispose();
|
||||
if (exitSystem)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GridBagConstraints makegbc(int x, int y, int width, int height)
|
||||
{
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridx = x;
|
||||
gbc.gridy = y;
|
||||
gbc.gridwidth = width;
|
||||
gbc.gridheight = height;
|
||||
gbc.insets = new Insets(1, 1, 1, 1);
|
||||
return gbc;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class TextDialog
|
||||
extends Dialog
|
||||
implements ActionListener
|
||||
{
|
||||
public TextDialog(Frame owner, String title, String textAreaText, String buttonText, boolean modal, int sizeX, int sizeY)
|
||||
{
|
||||
super(owner, title, modal);
|
||||
setBackground(Color.lightGray);
|
||||
setLocation(getToolkit().getScreenSize().width - sizeY, 0);
|
||||
|
||||
//Layout setzen und Komponenten hinzufügen
|
||||
GridBagLayout gbl = new GridBagLayout();
|
||||
GridBagConstraints gbc;
|
||||
setLayout(gbl);
|
||||
|
||||
//TextArea hinzufügen
|
||||
TextArea text = new TextArea(textAreaText, 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
gbc = MainFrameGui.makegbc(0, 0, 1, 1);
|
||||
gbc.weightx = 100;
|
||||
gbc.weighty = 100;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbl.setConstraints(text, gbc);
|
||||
add(text);
|
||||
|
||||
//Button
|
||||
Button button = new Button(buttonText);
|
||||
gbc = MainFrameGui.makegbc(0, 1, 1, 1);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.SOUTH;
|
||||
gbl.setConstraints(button, gbc);
|
||||
button.addActionListener(this);
|
||||
add(button);
|
||||
|
||||
pack();
|
||||
setSize(sizeX, sizeY);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
int i = getSize().height;
|
||||
int j = i / 20;
|
||||
int oldWidth = getSize().width;
|
||||
int oldHeight = getSize().height;
|
||||
|
||||
System.out.println(i + " - " + j);
|
||||
|
||||
while(i > -1)
|
||||
{
|
||||
//System.out.println(i);
|
||||
setSize(getSize().width, i);
|
||||
try
|
||||
{
|
||||
Thread.sleep(5);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
//nix
|
||||
}
|
||||
i = i - j;
|
||||
}
|
||||
setVisible(false);
|
||||
setSize(oldWidth, oldHeight);
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class arsc
|
||||
{
|
||||
static String DBUrl = "jdbc:mysql://194.231.30.146/arscdev?user=user&password=password";
|
||||
static String arsc_sid = "dhndewbz2798z23dzdewßdew";
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
MainFrameGui gui = new MainFrameGui();
|
||||
gui.setSize(480,300);
|
||||
gui.setVisible(true);
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
PreparedStatement pStmt = null;
|
||||
|
||||
conn = DriverManager.getConnection(DBUrl);
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("INSERT INTO arsc_users (id, user, lastping, ip, room, language, version, level, sid, lastmessageping) VALUES ('', 'javapgod', '', '', 'lounge', 'german', 'sockets', '1', 'abcdefg', '') ");
|
||||
}
|
||||
catch (SQLException sqlEx) { System.err.println(sqlEx.toString()); }
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
//nix
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Socket sock = new Socket("194.231.30.146", 12345);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
|
||||
OutputStream out = sock.getOutputStream();
|
||||
String line = "arsc_sid=abcdefg HTTP";
|
||||
out.write(line.getBytes());
|
||||
out.write('\r');
|
||||
out.write('\n');
|
||||
String blubb = new String();
|
||||
while ((blubb = in.readLine()) != null)
|
||||
{
|
||||
gui.messages.append(blubb);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
sock.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println(e.toString());
|
||||
//System.exit;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
//nix
|
||||
}
|
||||
//gui.messages.append("blah...\n");
|
||||
if (gui.cb.getState() == true)
|
||||
{
|
||||
gui.messages.setCaretPosition(99999999);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user