import java.awt.*;
import java.applet.Applet;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import javax.swing.Timer;
import javax.swing.*;
import java.applet.AudioClip;
import java.net.*;
public class JClient {
private Graphics BufferGraphics;
private Image offscreen;
private String currentScreen;
//NETWORKING VARIABLES
int port;
String servIP;
Socket mySocket;
SocketAddress server;
private PrintWriter toServer;
private BufferedReader fromServer;
private ServerListener receiver;
//WINDOW VARIABLES
JFrame frame;
extendedPanel panel;
public static void main(String[] args) throws IOException{
new JClient();
}
public JClient(){
currentScreen="mainmenu";
frame = new JFrame("I FUCKING HATE SWING WAHHHHHHHHHHH");
panel = new extendedPanel(new ImageIcon("GFX/GUI/"+currentScreen+".png"), 0, 0, 800, 600)
{
public void mousePressed(MouseEvent e)
{
toServer.print("CREATEACC ninja test");
toServer.flush();
//System.err.println("PRESSED");
}
};
Container content = frame.getContentPane();
content.setLayout(null);
content.add(panel);
frame.setDefaultCloseOperation(3);
frame.setSize(800, 600);
frame.setVisible(true);
frame.setResizable(false);
init();
makeContact();
}
private void init(){
//SERVER IP INFORMATION
servIP="127.0.0.1"; port=9999;
currentScreen="mainmenu";
}
private void makeContact(){
System.err.println("Making contact...");
try{
mySocket=new Socket(servIP,port);
System.out.println("Connected on "+servIP);
fromServer=new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
new ServerListener(this,fromServer);
toServer=new PrintWriter(new OutputStreamWriter(mySocket.getOutputStream()));
}catch(Exception e){}
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
///////// HANDLING MOUSE AND KEYBOARD INPUT /////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
}//END CLIENT
class ServerListener extends Thread{
JClient client;
BufferedReader in;
public ServerListener(JClient c,BufferedReader i){
client=c;
in=i;
start();
}
public void run(){
String msg="a";
System.out.println("thread started");
try{
System.out.println("inside the try");
while(msg!=null){
System.out.println("inside the loop");
System.out.println(""+msg);
msg=in.readLine();
}
System.out.println("done with loop");
}catch(Exception e){}
}
}//END SERVERLISTENER
class extendedPanel extends JPanel implements MouseListener, MouseMotionListener, KeyListener
{
JPanel panel;
ImageIcon pic;
Image image;
int x, y, w, h;
int mX, mY;
boolean ms_pressed = false;
public extendedPanel(ImageIcon p, int locX, int locY, int sizeW, int sizeH)
{
pic = p;
x = locX;
y = locY;
w = sizeW;
h = sizeH;
init();
}
private void init()
{
image = pic.getImage();
setOpaque(true); //indicates that this is indeed the bottom layer
setLocation(x,y);
setSize(w,h);
addMouseListener(this);
}
public int getMouseX()
{
return mX;
}
public int getMouseY()
{
return mY;
}
public void paintComponent(Graphics g)
{
Dimension dim = getSize();
int x, y;
// ensure proper background handling
if( isOpaque() ) { super.paintComponent( g ); }
// redraw image horizontal/vertical until panel is filled
for( y = 0; y < dim.height; y += h )
{
for( x = 0; x < dim.width; x += w )
pic.paintIcon( this, g, x, y );
}
}
public boolean getMouse()
{
return ms_pressed;
}
public void mouseClicked(MouseEvent e)
{
//ms_clicked = true;
}
public void mouseDragged(MouseEvent e)
{}
public void mouseMoved(MouseEvent e)
{}
public void mouseReleased(MouseEvent e)
{
//ms_pressed = false;
}
public void mouseExited(MouseEvent e)
{}
public void mouseEntered(MouseEvent e)
{}
public void mousePressed(MouseEvent e)
{
//ms_pressed = true;
}
public void keyPressed(KeyEvent e)
{
/* DIFFERENT KEYS:::
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_LEFT:
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_SPACE:
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_F1:
*/
}
public void keyReleased(KeyEvent e)
{}
public void keyTyped(KeyEvent e)
{}
}