package mysqlconnector;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.sql.*;
import java.util.*;
public class beat extends Applet implements ActionListener
{
public static TextArea area;
public static String text;
public static String outText;
public static TextField field;
public static String command;
public static String strSQL;
public static Connection con;
public static ResultSet result;
public static Font TimesR = new Font("MonoSpaced", Font.BOLD, 15);
public void init()
{
setLayout( new BorderLayout() );
add( "Center", area = new TextArea() );
area.setFont(TimesR);
area.setText("***** Welcome to the Java Text RPG! *****\n");
area.setEditable(false);
add( "South", field = new TextField() );
field.addActionListener ( this );
field.requestFocusInWindow();
}
public void connectMySQL() {
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Properties props = new Properties();
props.put("user", "root");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jgame", props);
area.append("Database is connected!\n");
PreparedStatement statement = con.prepareStatement( "select * from members");
ResultSet result = statement.executeQuery();
while(result.next())
{
area.append(result.getString(2)+ "\n");
}
}
catch(Exception err)
{
}
}
public void start() {
connectMySQL();
}
public static void appendIt() {
String text = field.getText();
area.append("> "+field.getText() + "\n");
// STATUS *************************************************
if ("status".equalsIgnoreCase(text)) {
area.append("Checking status..."); //add onto text area
try {
if (!con.isClosed()) {
area.append("\n > ONLINE");
}else {
area.append("\n > OFFLINE");
}
}catch (Exception eer) {
area.append("\nSQL Error: " + eer.toString() + "\nGet Local Msg: " + eer.getLocalizedMessage()); //add onto text area
}
// END STATUS *************************************************
}
}
public void actionPerformed(ActionEvent e)
{
connectMySQL();
appendIt();
if (con == null) {
area.append("> OFFLINE\n");
}else {
area.append("> ONLINE\n");
}
field.setText(""); // clear input box
}
public void stop()
{
}
}