PDA

View Full Version : 562 GUI Client



Steve
October 30th, 2010, 04:23
This is clientsided
Here's a picture(you can change themes)
590
Yeah uhmmmm, I did this in a BAD way, well compared to the other way i could have done it. I coulda just extended the client class but oh well. I decided to change something to a JPanel instead lolololol. Well anyway only thing you need to edit in your client is this. Oh and i posted this because i know a lot of you can't do it yourself.

Go into Class158.java and find


public static Applet aFrame2095; Change it to
public static JPanel aFrame2095; And import



import javax.swing.JPanel;Then go to Applet_Sub1.java and find


Class158.aFrame2095 = new Frame();And replace it with

Class158.aFrame2095 = new JPanel();And import


import javax.swing.JPanel;Now replace this,

Class158.aFrame2095.setTitle("blahblah");
Class158.aFrame2095.setResizable(true);
Class158.aFrame2095.addWindowListener(this);
Class158.aFrame2095.setVisible(true);
Class158.aFrame2095.toFront(); with


Class158.aFrame2095.setBackground(Color.BLACK);
Class158.aFrame2095.setVisible(true);
There. Now Add these to files into your clients source,

ClientFrame.java



import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;

/**
*
* @author Stephen
*/
public class ClientFrame extends JFrame implements ActionListener {

private Dimension oldSize;
private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private String[] fileMenuItems = {"File", "Close"};
private String FRAME_TITLE = "562 GUI";
public static JPanel gamePane;
private JButton screenShot = new JButton("Screenshot");

public ClientFrame(String[] args) {
client.main(args);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
setLayout(new BorderLayout());
setTitle(FRAME_TITLE);
setSize(780, 560);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar();
setClientonFrame();
}

public static void main(final String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new ClientFrame(args).setVisible(true);
}
});
}

private void setJMenuBar() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false );

for (String newMenuItem : fileMenuItems) {
if (newMenuItem.equals("Close")) {
fileMenu.add(new JSeparator());
}
JMenuItem newItem = new JMenuItem(newMenuItem);
newItem.setActionCommand(newMenuItem);
newItem.addActionListener(this);
fileMenu.add(newItem);
}

menuBar.add(fileMenu);
screenShot.setActionCommand("Screenshot");
screenShot.addActionListener(this);
menuBar.add(screenShot);
menuBar.setBorderPainted(true);
setJMenuBar(menuBar);
}

private void setClientonFrame() {
gamePane = new JPanel();
gamePane.setLayout(new BorderLayout());
gamePane.add(Class158.aFrame2095);
add(gamePane);
}

@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("Screenshot")) {
try {
new ScreenShot();
} catch (AWTException ex) {
Logger.getLogger(ClientFrame.class.getName()).log( Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ClientFrame.class.getName()).log( Level.SEVERE, null, ex);
}
} else if (command.equals("Close")) {
System.exit(0);
}
}
}
And then add this file,

ScreenShot.java



import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
*
* @author Stephen
*/
class ScreenShot {

private String path = "./images/";
private int fileAmts;

public ScreenShot() throws AWTException, IOException {
File filePath = new File(path);
if (filePath.list() != null) {
for (int i = 0; i < filePath.list().length; i++) {
fileAmts++;
}
}
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(ClientFrame.gamePane.getLocationOnScreen ().x, ClientFrame.gamePane.getLocationOnScreen().y, ClientFrame.gamePane.getWidth(), ClientFrame.gamePane.getHeight()));
File newFile = new File(path + "screenshot" + (fileAmts + 1) + ".png");
ImageIO.write(image, "png", newFile);
}
}
Alright that should be it. The gui is simple, you guys can build off of it. Like here's how to add a new Menu,

You would add

private JMenu menumanehereMenu = new JMenu("menunamehere"); Below
private JMenu fileMenu = new JMenu("File");Just to keep it organized :p, then for your options on the menu you would add,



private String[] menunamehereMenuItems = {"Option1", "Option2", "Etc..."};
Then find


private void setJMenuBar() {
And under


for (String newMenuItem : fileMenuItems) {
if (newMenuItem.equals("Close")) {
fileMenu.add(new JSeparator());
}
JMenuItem newItem = new JMenuItem(newMenuItem);
newItem.setActionCommand(newMenuItem);
newItem.addActionListener(this);
fileMenu.add(newItem);
}
you would add something like



for (String newMenuItem : menunamehereMenuItems) {
if (newMenuItem.equals("Close")) {
menunamehereMenu.add(new JSeparator());
}
JMenuItem newItem = new JMenuItem(newMenuItem);
newItem.setActionCommand(newMenuItem);
newItem.addActionListener(this);
menunamehereMenu.add(newItem);
}
Then below it you would add



menuBar.add(menunamehereMenu);
Then to make it do actions find
actionPerformed(ActionEvent e) then add like


if (command.equals("themenuitemselected(like "option2")")) {
//Do stuff
}
I made it simple because i got bored with something else and decided to procrastinate. I could have made it look 100x better.

EDIT: Not sure if a said this but create a directory in your src folder called images,
And change your run.bat to,


@echo off
java -cp bin;lib/clientlibs.jar ClientFrame 0 live english game0
pause

Wombat
October 30th, 2010, 04:24
nice job

Nosz
October 30th, 2010, 07:00
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());

This doesnt work...

Steve
October 30th, 2010, 11:49
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());

This doesnt work...

Eh, I'll see what's wrong with it later today.

apache ah64
November 27th, 2010, 14:43
i did try it but most of codes are not even into my client LOL!

vanweele
December 11th, 2010, 04:50
Very usefull tool steve, you did well on the tut :\
yeah sorry about lastnight er w/e. not feelign so great, but anyways, as Nosz said that code didnt work for me either, but this is very usefull, i really really like the screenshot idea.
well done.
i get these errors:
Only the registered members can see the link.

alboboy94
December 11th, 2010, 04:53
what a nub... always commin up with new shit :D

good job.

vanweele
December 11th, 2010, 04:57
what a nub... always commin up with new shit :D

good job.

steve is very good with 562 stuff, i have a lot of respect for steve cause he puts up with a lot of my shit :\ but he stopped me from leaving r-l, always trys to help me, and encourages me to do things on my own even if i know i can't..
but yeah, this is a good job here.

alboboy94
December 11th, 2010, 04:59
steve is very good with 562 stuff, i have a lot of respect for steve cause he puts up with a lot of my shit :\ but he stopped me from leaving r-l, always trys to help me, and encourages me to do things on my own even if i know i can't..
but yeah, this is a good job here.

dats whut im saying. Who doesnt love steve :o?

vanweele
December 11th, 2010, 05:10
dats whut im saying. Who doesnt love steve :o?

idk, but i need help on this gui thingy unfortantly :\ i've been collecting java guides for steve and emily, imma read them when im going up north here in a week, ill read them in the car off my laptop.

Emily
December 11th, 2010, 05:15
idk, but i need help on this gui thingy unfortantly :\ i've been collecting java guides for steve and emily, imma read them when im going up north here in a week, ill read them in the car off my laptop.
Appears you are missing the imports for those, i recommend download eclipse & using it, it will give you the import names by hovering over the code.

Steve
December 11th, 2010, 05:22
Lol this thing is shit, i wouldn't use it.

vanweele
December 11th, 2010, 05:24
eh, idk how to use eclipse, i know you have it, most likely, if not then sorry, but could you please do it?
it'd probally take you Emily, 5 minutes? me..hmm..lets see, 1 help topic, 2 posts, both from me double posting, some complaining..and what not, :P
but yeah if you could do that i'd really appreciaite it, and i owe you an appoligy too, what i said lastnight on the worldmap thread was unaceptable, if you didnt read it then good, if you did, then i'm sorry.


Lol this thing is shit, i wouldn't use it.

it may be but it has the screenshot tab, thats ALL i need. >_<..

vanweele
December 11th, 2010, 06:07
kay changed the code steve posted to:



import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.UIManager;

/**
*
* @author Stephen
*/
public class ClientFrame extends JFrame implements ActionListener {

private Dimension oldSize;
private JMenuBar menuBar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private String[] fileMenuItems = {"File", "Close"};
private String FRAME_TITLE = "562 GUI";
public static JPanel gamePane;
private JButton screenShot = new JButton("Screenshot");

public ClientFrame(String[] args) {
ClientFrame client = null;
client.main(args);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
setLayout(new BorderLayout());
setTitle(FRAME_TITLE);
setSize(780, 560);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar();
setClientonFrame();
}

public static void main(final String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new ClientFrame(args).setVisible(true);
}
});
}

private void setJMenuBar() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false );

for (String newMenuItem : fileMenuItems) {
if (newMenuItem.equals("Close")) {
fileMenu.add(new JSeparator());
}
JMenuItem newItem = new JMenuItem(newMenuItem);
newItem.setActionCommand(newMenuItem);
newItem.addActionListener(this);
fileMenu.add(newItem);
}

menuBar.add(fileMenu);
screenShot.setActionCommand("Screenshot");
screenShot.addActionListener(this);
menuBar.add(screenShot);
menuBar.setBorderPainted(true);
setJMenuBar(menuBar);
}

private void setClientonFrame() {
gamePane = new JPanel();
gamePane.setLayout(new BorderLayout());
gamePane.add(Class158.aFrame2095);
add(gamePane);
}

@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("Screenshot")) {
try {
new ScreenShot();
} catch (AWTException ex) {
Logger.getLogger(ClientFrame.class.getName()).log( Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ClientFrame.class.getName()).log( Level.SEVERE, null, ex);
}
} else if (command.equals("Close")) {
System.exit(0);
}
}
}

and it worked. now im getting the compile error for color.black.

ghrim
December 11th, 2010, 17:13
for the color.BLACK you need to import the java color manager into Applet_Sub1 file.

import java.awt.Color;

Also make sure the "c" in "color" is Capitalized for both the import and the statement.

vanweele
December 11th, 2010, 17:23
all this update did was make cmd start, and the client wont start, just cmd comes up.
thats it ;p

ghrim
December 11th, 2010, 17:31
Umm did you change your run.bat file to what Steve told you to change it?

vanweele
December 11th, 2010, 18:05
Umm did you change your run.bat file to what Steve told you to change it?

that run.bat file makes my cmd freak out..

zakal
August 10th, 2011, 17:55
When i run it, I get errors. its impossible to count them because they are coming so fast, and the error text never stops coming..its errors running on the run.bat 24/7.. lol

own4g3
August 10th, 2011, 18:58
When i run it, I get errors. its impossible to count them because they are coming so fast, and the error text never stops coming..its errors running on the run.bat 24/7.. lol

Dumbass
You bumped a 7 month old thread and gratz on your first post.

iiNarbz
September 2nd, 2011, 02:00
Can someone convert this tutorial to 562 Loading 602 please?