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
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