Jump to content

Divine-X

Member
  • Content count

    1,660
  • Joined

  • Last visited

Everything posted by Divine-X

  1. [url]http://kotaku.com/hackers-claim-takedown-of-battle-net-league-of-legends-1491906080?utm_campaign=Socialflow_Kotaku_Facebook&utm_source=Kotaku_Facebook&utm_medium=Socialflow[/url] Omg wow, such smart, much DDOS
  2. Okay, I know what the problem is, I just don't know how to fix it. The problem is when I create a new file my code would get everything from the player class but not the hp. And when I try to load the game I would get an error since [code]<hp>AMOUNT</hp>[/code] isn't in the xml file. I feel like and it probably is because the variable is static but if it's not static I wouldn't be able to change the value. When I create a new game/file, what the game makes: [code]<player> <username>Storm</username> <password>k</password> <attack>5</attack> <defence>1</defence> <magic>1</magic> <warrior>false</warrior> <archer>false</archer> <mage>false</mage> <rights>1</rights> </player>[/code] What it's missing: [code]<player> <username>Storm</username> <password>k</password> [COLOR="#FF0000"] <hp>100</hp>[/COLOR] <attack>5</attack> <defence>1</defence> <magic>1</magic> <warrior>false</warrior> <archer>false</archer> <mage>false</mage> <rights>1</rights> </player>[/code] Load file code: [code] public static void load(Player p) { String name = JOptionPane.showInputDialog("Please enter your username"); if(name.length() == 0) { JOptionPane.showMessageDialog(null, "Enter a name longer than 0 characters!"); load(p); } String pass = JOptionPane.showInputDialog("Please enter your password"); if(pass.length() == 0) { JOptionPane.showMessageDialog(null, "Enter a password longer than 0 characters!"); load(p); } else { try { XML playerFile = new XML("data/games/"+name+".xml"); playerFile.setByElement("player"); for(int i = 0; i < playerFile.getElements().size(); i++) { Map<String, String> element = playerFile.getElements().get(i); String username = playerFile.getStringByTag(element, "username"); p.setUsername(username); String password = playerFile.getStringByTag(element, "password"); p.setPassword(password); int hp = playerFile.getIntByTag(element, "hp"); p.setHp(hp); int attack = playerFile.getIntByTag(element, "attack"); p.setAttack(attack); int defence = playerFile.getIntByTag(element, "defence"); p.setDefence(defence); int magic = playerFile.getIntByTag(element, "magic"); p.setMagic(magic); boolean warrior = Boolean.parseBoolean(playerFile.getStringByTag(element, "warrior")); p.setWarrior(warrior); boolean archer = Boolean.parseBoolean(playerFile.getStringByTag(element, "archer")); p.setArcher(archer); boolean mage = Boolean.parseBoolean(playerFile.getStringByTag(element, "mage")); p.setMage(mage); int rights = playerFile.getIntByTag(element, "rights"); p.setRights(rights); } } catch(Exception e) { JOptionPane.showMessageDialog(null, "Error with loading!", "Alert", JOptionPane.INFORMATION_MESSAGE); e.printStackTrace(); } } }[/code] XML stuff: [code]public class XML { private List<Map<String, String>> elements = new ArrayList<Map<String, String>>(); private BufferedReader reader; public XML(final String file) throws IOException { reader = new BufferedReader(new FileReader(file)); } public void setByElement(String name) throws IOException { String line; String endName = "</" + name +">"; name = "<" + name + ">"; while ((line = reader.readLine()) != null) { if (line.contains(name)) { Map<String, String> element = new HashMap<String, String>(); while (!(line = reader.readLine()).contains(endName)) { element.put(line.substring(line.indexOf("<") + 1, line.indexOf(">")), line.substring(line.indexOf(">") + 1, line.lastIndexOf("<"))); } elements.add(element); } } reader.close(); } public List<Map<String, String>> getElements() { return elements; } public String getStringByTag(Map<String, String> element, String name) { return element.get(name); } public long getLongByTag(Map<String, String> element, String name) { return Long.parseLong(element.get(name)); } public int getIntByTag(Map<String, String> element, String name) { return Integer.parseInt(element.get(name)); } public short getShortByTag(Map<String, String> element, String name) { return Short.parseShort(element.get(name)); } public byte getByteByTag(Map<String, String> element, String name) { return Byte.parseByte(element.get(name)); } }[/code] Player: [code] package text.game.player; public class Player { String username, password; [COLOR="#FF0000"] private static int hp = 100;[/COLOR] private int attack = 5; private int defence = 1; private int magic = 1; private boolean warrior = false; private boolean archer = false; private boolean mage = false; private int rights = 0; private Inventory inventory; /** * @return the username */ public String getUsername() { return username; } /** * @param username the username to set */ public void setUsername(String username) { this.username = username; } /** * @return the password */ public String getPassword() { return password; } /** * @param password the password to set */ public void setPassword(String password) { this.password = password; } [COLOR="#FF0000"] /** * @return the hp */ public int getHp() { return hp; }[/COLOR] [COLOR="#FF0000"] /** * @param newHp the hp to set */ public void setHp(int newHp) { Player.hp = newHp; }[/COLOR] /** * @return the rights */ public int getRights() { return rights; } /** * @param rights the rights to set */ public void setRights(int rights) { this.rights = rights; } /** * @return the warrior */ public boolean isWarrior() { return warrior; } /** * @param warrior the warrior to set */ public void setWarrior(boolean warrior) { this.warrior = warrior; } /** * @return the archer */ public boolean isArcher() { return archer; } /** * @param archer the archer to set */ public void setArcher(boolean archer) { this.archer = archer; } /** * @return the mage */ public boolean isMage() { return mage; } /** * @param mage the mage to set */ public void setMage(boolean mage) { this.mage = mage; } /** * @return the attack */ public int getAttack() { return attack; } /** * @param attack the attack to set */ public void setAttack(int attack) { this.attack = attack; } /** * @return the defence */ public int getDefence() { return defence; } /** * @param defence the defence to set */ public void setDefence(int defence) { this.defence = defence; } /** * @return the magic */ public int getMagic() { return magic; } /** * @param magic the magic to set */ public void setMagic(int magic) { this.magic = magic; } public Inventory getInventory() { return inventory; } public void setInventory(Inventory inventory) { this.inventory = inventory; } } [/code] Error: [code]Item info loaded: 2 java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at text.game.managers.XML.getIntByTag(XML.java:49) at text.game.managers.FileManager.load(FileManager.java:92) at text.gui.GUI$4.actionPerformed(GUI.java:87) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.AbstractButton.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$400(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)[/code]
  3. I've never done any painting in Java so I'm completely blank on it. What I want to learn is how to basically paint a rectangle on a GUI and text overlay it saying 100/100 for the hp and have the rectangle update with the amount of health the player has. So basically this: [img]http://i.imgur.com/CxkFqui.png?1?2866[/img]
  4. [video=youtube;vaeA43-U5kM]http://www.youtube.com/watch?v=vaeA43-U5kM[/video]
  5. Divine-X

    Ghosts vs BF4

    [quote name='bigboysss']ghosts ftw[/QUOTE] Battlefield 4.
  6. Divine-X

    Python?

    [quote name='SSion']What is the best language to learn first? I heard its python.[/QUOTE] When I started I learned HTML(not considered a real language) and then I went to Java. I would say Java is the 1st language you should learn since a lot of companies and machines use Java. But then they also use C <.<.
  7. [quote name='Trey']You're abusing/misunderstanding the point of the static keyword. When a variable is static, it is the same value for all instances of that class, rather than each instance having its own separate value such as for non-static variables. This mean every instance of Player will have the same hp, which is almost assuredly not intended. You say that you make it static so that you can change it, and I don't understand why this is. You have setters/getters for all your other instance variables, so why is hp any different? Are you using serialization (Serializable interface, read/writeObject)? The fact that it is static is also probably why it isn't saved in the XML. It doesn't make sense to save static variables, so they aren't.[/QUOTE] If I have the regular getter/setter setup and I do some calculations for the damage done to the player, and I try to save the game, the player file will stay at[code]<hp>100</hp>[/code] when in the game itself the player is at for example 70hp.
  8. [quote name='Emily']Why is 'hp' static? You're using setters, so I'm assuming you have getters as well. This line: [IMG]return Integer.parseInt(element.get(name));[/IMG] parseInt is meant for strings only, which the value could be an object in this case. Should be: [CODE] return Integer.parseInt(element.get(name).toString()); [/CODE] Only thing I can see on a quick glance.[/QUOTE] If I didn't make it static I wouldn't be able to change the players HP, it'll only change the classes HP value temporarily.
  9. [quote name='zizema660']hey so I want to start hosting my 317 [pi] but for some reason people cant load the cache from my website so whatever if I buy a vps will it help with that problem if I purchase a vps what files do you think I will have to change and how do I change them? thanks for looking guys[/QUOTE] VPS: Virtual Private Server, it's a virtual machine(computer) that is sold by an Internet Hosting Service. A VPS runs it's own copy of an operating system. It's basically a virtual computer that never turns off(unless the company is doing something). They probably can't load the cache because it's probably not being downloaded properly. I don't know, I'm not a 317 person. And buying a vps will not help the problem. People buy VPSs to host their server so people can enjoy it at anytime of the day.
  10. [quote name='Friss']Well where do you create the file? From a quick look over I don't see where you create the file. Also your set hp you use Player.hp while everywhere else you use this.hp any reason why? Sent from my XT1034 using Tapatalk[/QUOTE] [code] public static void create(Player p) { try { String username = JOptionPane.showInputDialog("Please enter a username"); String password = JOptionPane.showInputDialog("Please enter a password"); if(password.length() == 0) { JOptionPane.showMessageDialog(null, "Enter a password greater than 0!"); create(p); } else { File f = new File("data/games/"+username+".xml"); if(f.exists()) { JOptionPane.showMessageDialog(null, "This file already exists!", "Alert", JOptionPane.ERROR_MESSAGE); create(p); } else { p.setUsername(username); p.setPassword(password); save(p); } } } catch(Exception e) { JOptionPane.showMessageDialog(null, "There is no such directory.", "Alert", JOptionPane.INFORMATION_MESSAGE); } }[/code] [code] public static void save(Player p) { try { XStream xst = FileManager.getXStream(); xst.toXML(p, new FileOutputStream( "data/games/"+p.getUsername()+".xml")); } catch(Exception e) { System.out.println("Error with saving player!"); } }[/code] And I use "Player.hp" because eclipse said it should be accessed in a static way.
  11. [quote name='yehimnick']and yes i do got team viewer[/QUOTE] PM your ID and Pass
  12. [quote name='yehimnick'][url]http://gyazo.com/ef142e2fb1f0a4ee0bb84449cca67476[/url] <--- compiler code [url]http://gyazo.com/fb6a843afc377b09aad3f6e0e44f6a25[/url] <--- variable[/QUOTE] Do you have Teamviewer? If so pm me your ID and Pass
  13. [quote name='yehimnick']:( weird this is hard[/QUOTE] Can you post your compilers code?
  14. [code]public void drawLoginScreen(boolean flag) { if (normalLogin == true) { resetImageProducers(); aRSImageProducer_1109.initDrawingArea(); aBackground_966.drawBackground(0, 0); char c = '\u0168'; char c1 = '\310'; } if(loginScreenState == 0) { int i = c1 / 2 + 80; smallText.method382(0x75a9a9, c / 2, onDemandFetcher.statusString, i, true); i = c1 / 2 - 20; chatTextDrawingArea.method382(0xffff00, c / 2, "Welcome to RuneScape", i, true); i += 30; int l = c / 2 - 80; int k1 = c1 / 2 + 20; aBackground_967.drawBackground(l - 73, k1 - 20); chatTextDrawingArea.method382(0xffffff, l, "New User", k1 + 5, true); l = c / 2 + 80; aBackground_967.drawBackground(l - 73, k1 - 20); chatTextDrawingArea.method382(0xffffff, l, "Existing User", k1 + 5, true); } if(loginScreenState == 2) { int j = c1 / 2 - 40; } if(loginMessage1.length() > 0) { chatTextDrawingArea.method382(0xffff00, c / 2, loginMessage1, j - 15, true); chatTextDrawingArea.method382(0xffff00, c / 2, loginMessage2, j, true); j += 30; } else { chatTextDrawingArea.method382(0xffff00, c / 2, loginMessage2, j - 7, true); j += 30; } chatTextDrawingArea.method389(true, c / 2 - 90, 0xffffff, "Username: " + myUsername + ((loginScreenCursorPos == 0) & (loopCycle % 40 < 20) ? "@[email protected]|" : ""), j); j += 15; chatTextDrawingArea.method389(true, c / 2 - 88, 0xffffff, "Password: " + TextClass.passwordAsterisks(myPassword) + ((loginScreenCursorPos == 1) & (loopCycle % 40 < 20) ? "@[email protected]|" : ""), j); j += 15; if(!flag) { int i1 = c / 2 - 80; int l1 = c1 / 2 + 50; aBackground_967.drawBackground(i1 - 73, l1 - 20); chatTextDrawingArea.method382(0xffffff, i1, "Login", l1 + 5, true); i1 = c / 2 + 80; aBackground_967.drawBackground(i1 - 73, l1 - 20); chatTextDrawingArea.method382(0xffffff, i1, "Cancel", l1 + 5, true); } if(loginScreenState == 3) { chatTextDrawingArea.method382(0xffff00, c / 2, "Create a free account", c1 / 2 - 60, true); int k = c1 / 2 - 35; chatTextDrawingArea.method382(0xffffff, c / 2, "To create a new account you need to", k, true); k += 15; chatTextDrawingArea.method382(0xffffff, c / 2, "go back to the main RuneScape webpage", k, true); k += 15; chatTextDrawingArea.method382(0xffffff, c / 2, "and choose the red 'create account'", k, true); k += 15; chatTextDrawingArea.method382(0xffffff, c / 2, "button at the top right of that page.", k, true); k += 15; int j1 = c / 2; int i2 = c1 / 2 + 50; aBackground_967.drawBackground(j1 - 73, i2 - 20); chatTextDrawingArea.method382(0xffffff, j1, "Cancel", i2 + 5, true); } aRSImageProducer_1109.drawGraphics(500, super.graphics, 155); if(welcomeScreenRaised) { welcomeScreenRaised = false; aRSImageProducer_1107.drawGraphics(0, super.graphics, 128); aRSImageProducer_1108.drawGraphics(371, super.graphics, 202); aRSImageProducer_1112.drawGraphics(265, super.graphics, 0); aRSImageProducer_1113.drawGraphics(265, super.graphics, 562); aRSImageProducer_1114.drawGraphics(171, super.graphics, 128); aRSImageProducer_1115.drawGraphics(171, super.graphics, 562); } else if(normalLogin == false) { worldLoginScreen(); resetImageProducers(); aRSImageProducer_1109.initDrawingArea(); Sprite loginTest = new Sprite("Login/login"); loginTest.drawSprite(0, 0); } if(loginMessage1.length() > 0) { chatTextDrawingArea.method382(0x00ccff, 255, loginMessage2, 60, true); } else { chatTextDrawingArea.method382(0x00ccff, 255, loginMessage2, 60, true); } if (loginButtonint == 0) { Sprite LOGINBUTTON = new Sprite("Login/LOGINBUTTON"); LOGINBUTTON.drawSprite(382, 89); } else if (loginButtonint == 1) { Sprite LOGINBUTTON0 = new Sprite("Login/LOGINBUTTON1"); LOGINBUTTON0.drawSprite(382, 89); } if (!rememberMe) { Sprite unclickedR = new Sprite("Login/unclicked"); unclickedR.drawSprite(13, 130); } else if (rememberMe) { Sprite clickedR = new Sprite("Login/clicked"); clickedR.drawSprite(13, 130); } if (textbox == 0) { Sprite textbox = new Sprite("Login/textbox"); textbox.drawSprite(13, 91); } else if (textbox == 1) { Sprite textbox1 = new Sprite("Login/textbox1"); textbox1.drawSprite(13, 91); } if (textbox1 == 0) { Sprite textbox = new Sprite("Login/textbox"); textbox.drawSprite(197, 91); } else if (textbox1 == 1) { Sprite textbox1 = new Sprite("Login/textbox1"); textbox1.drawSprite(197, 91); } /** Font types **/ //chatTextDrawingArea.method389(true, 18, 0x00f0ff, "" + capitalize(myUsername) + ((loginScreenCursorPos == 0) & (loopCycle % 40 < 20) ? "|" : ""), 110); aTextDrawingArea_1271.method389(false,18,0x000000,"" + (myUsername) + ((loginScreenCursorPos == 0) & (loopCycle % 40 < 20) ? "|" : ""), 110); //chatTextDrawingArea.method389(true, 203, 0x00f0ff, "" + TextClass.passwordAsterisks(myPassword) + ((loginScreenCursorPos == 1) & (loopCycle % 40 < 20) ? "|" : ""), 110); aTextDrawingArea_1271.method389(false,203,0x000000,"" + TextClass.passwordAsterisks(myPassword) + ((loginScreenCursorPos == 1) & (loopCycle % 40 < 20) ? "|" : ""), 110); aRSImageProducer_1109.drawGraphics(171, super.graphics, 133); if(welcomeScreenRaised) { welcomeScreenRaised = false; aRSImageProducer_1107.drawGraphics(0, super.graphics, 128); aRSImageProducer_1108.drawGraphics(371, super.graphics, 202); aRSImageProducer_1112.drawGraphics(265, super.graphics, 0); aRSImageProducer_1113.drawGraphics(265, super.graphics, 562); aRSImageProducer_1114.drawGraphics(171, super.graphics, 128); aRSImageProducer_1115.drawGraphics(171, super.graphics, 562); } } }[/code] I tried my best to clean it. Edit: You might need to delete the last } but yeah.
  15. [quote name='Hope']I can help you out if you still need it. Skype: worldofclayton[/QUOTE] But I don't want to redownload skype x-x
  16. [quote name='Vexia']You can use a JProgressBar. [URL="http://docs.oracle.com/javase/6/docs/api/javax/swing/JProgressBar.html"]http://docs.oracle.com/javase/6/docs/api/javax/swing/JProgressBar.html[/URL][/QUOTE] I tried but when the player has for example 80 hp. It'll still say 100%. My other problem with JProgress bar is that I don't want it to say 100% I want it to say 100/100
  17. [quote name='milf hunter']Seems interesting haha I think I have an idea, but I might be wrong so nevermind :P[/QUOTE] Any help would be appreciated, I don't know anything about painting so any help would do
  18. [quote name='Arix']Oh easy. Go on codiction I'll show you.[/QUOTE] Kk mts
  19. Okay, my problem is that I have GUI and I want to have a method that I can use that'll update the JTextArea with the new string. But I keep getting this error [code] Exception in thread "main" java.lang.NullPointerException at text.gui.GUI.updateTextArea(GUI.java:138) at text.game.Test.intro(Test.java:10) at text.gui.GUI.main(GUI.java:50) [/code] Here's all the code I have that involves the text area, am I missing something, I don't know what's wrong. [code]private JTextArea textArea;[/code] [code] public static void main(String[] args) { /*try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch(Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { GUI frame = new GUI(); Test.intro(); } });*/ GUI frame = new GUI(); frame.setVisible(true); Test.intro(); }[/code] [code] final JTextArea textArea = new JTextArea(); textArea.setBackground(new Color(176, 224, 230)); scrollPane.setViewportView(textArea); textArea.setEditable(false);[/code] [code] textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER) { inputString = textField.getText(); textArea.append(inputString+"\n"); textField.setText(""); } } });[/code] [code] public void updateTextArea(String message) { textArea.append(textArea.getText() + message + "\n"); textArea.selectAll(); int x = textArea.getSelectionEnd(); textArea.select(x, x); }[/code] [code]public class Test { static GUI frame = new GUI(); public static void intro() { frame.updateTextArea("Testing"); } }[/code] :confused:
  20. Thank you very much! That fixed all of my problems, now I can continue working on this.
  21. [quote name='Emily']For starters, from what you've provided; you are missing these imports on top of whatever classes are the 'Player', 'Commands', and 'FileManager'. [CODE] import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; [/CODE] You can clean that up to: [CODE] import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.EmptyBorder; [/CODE] [IMG]http://i.imgur.com/sixkYKa.png[/IMG] All I did was remove the calls to the Player, Commands, and FileManager class (since I don't have those). Your code currently works how you have it, within the GUI class (once you set it visible, which I don't see?). What I think you are missing is a get on the textArea. [CODE] /** * Returns the main chat area * [MENTION=184045]return[/MENTION] Initialized Text Area */ public JTextArea getTextArea() { return textArea; } [/CODE] So ideally after you've initialized the GUI class (where ever you are doing this), you can call the textArea through that method. [CODE] GUI gui = new GUI(); gui.setVisible(true); gui.getTextArea().append("Text would be the parameter here" + "/n"); [/CODE] Your code: [CODE] import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class GUI extends JFrame { private static final long serialVersionUID = -7046170369686574274L; private JPanel contentPane; private JTextField input; private JTextArea textArea; public String commands = ""; public String text = ""; private JProgressBar progressBar; public void printTextLine(String message) { textArea.append(message+"\n"); } /** * Returns the main chat area * [MENTION=184045]return[/MENTION] Initialized Text Area */ public JTextArea getTextArea() { return textArea; } public static void main(String[] args) { GUI gui = new GUI(); gui.setVisible(true); } /** * Create the frame. */ public GUI() { super("Text Based Game - Storm"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setBounds(100, 100, 450, 326); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmCreate = new JMenuItem("Create"); mntmCreate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); mnFile.add(mntmCreate); JMenuItem mntmSave = new JMenuItem("Save"); mnFile.add(mntmSave); JMenuItem mntmLoad = new JMenuItem("Load"); mnFile.add(mntmLoad); JMenuItem mntmExit = new JMenuItem("Exit (no save)"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mnFile.add(mntmExit); JMenuItem mntmLogin = new JMenuItem("Login"); mntmLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); menuBar.add(mntmLogin); contentPane = new JPanel(); contentPane.setBackground(new Color(210, 105, 30)); contentPane.setForeground(Color.BLACK); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); input = new JTextField(); input.setForeground(new Color(0, 128, 128)); input.setFont(new Font("SansSerif", Font.BOLD, 12)); input.setBackground(new Color(128, 0, 0)); input.addKeyListener(new KeyAdapter() { [MENTION=15855]Over[/MENTION]ride public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER) { text = input.getText(); textArea.append("> "+text+"\n"); input.setText(""); } } }); input.setBounds(10, 232, 236, 28); contentPane.add(input); input.setColumns(10); JLabel lblEnterCommandsHere = new JLabel("Enter Commands Here"); lblEnterCommandsHere.setBounds(60, 206, 135, 14); contentPane.add(lblEnterCommandsHere); JLabel label = new JLabel(""); label.setIcon(new ImageIcon(".\\resources\\pictures\\logo.png")); label.setBounds(256, 17, 168, 177); contentPane.add(label); JProgressBar progressBar = new JProgressBar(); progressBar.setStringPainted(true); progressBar.setToolTipText("HP"); progressBar.setBounds(256, 206, 168, 14); contentPane.add(progressBar); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 17, 236, 177); contentPane.add(scrollPane); textArea = new JTextArea(); textArea.setBackground(Color.CYAN); textArea.setAutoscrolls(true); scrollPane.setViewportView(textArea); } } [/CODE][/QUOTE] Thanks! I'll try this out soon. I set the GUI to visible in a different file because I was testing stuff. Edit: Okay, I tried out what you said but I can't really test if it works since after I click login and login it freezes. My FileManager isn't the problem but the problem is when I call this [code] public static void start() { frame.getTextArea().append("Starting game..."); }[/code] from the load method in FileManager after they've logged in, it freezes my GUI. Edit: It's like if I don't send the text on startup it wont display at all. [code] public static void main(String args[]) { GUI frame = new GUI(); frame.setVisible(true); frame.getTextArea().append("Welcome to Project Solstice.\n" + "I am your game Advisor: Reshieram." + " If you need a list of commands type: commands.\n"); }[/code] That shows the text in the GUI [img]http://img834.imageshack.us/img834/8964/2qtb.png[/img] [code] public static void main(String args[]) { GUI frame = new GUI(); frame.setVisible(true); Room.start(); }[/code] This wont display the text [code]package text.game; import text.gui.GUI; public class Room { static GUI frame = new GUI(); public static void start() { frame.printTextLine("Starting game..."); frame.getTextArea().append("Starting game..."); } } [/code] [img]http://img36.imageshack.us/img36/3113/3rrz.png[/img]
  22. [code]package text.gui; import java.awt.Color; public class GUI extends JFrame { private static final long serialVersionUID = -7046170369686574274L; private JPanel contentPane; private Commands cmds; private JTextField input; private JTextArea textArea; public String commands = ""; public String text = ""; private Player p = new Player(); private JProgressBar progressBar; public void printTextLine(String message) { // textArea.append(textArea.getText() + message + "\n"); //textArea.selectAll(); //int x = textArea.getSelectionEnd(); //textArea.select(x, x); textArea.append(message+"\n"); } /** * Create the frame. */ public GUI() { super("Text Based Game - Storm"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setBounds(100, 100, 450, 326); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmCreate = new JMenuItem("Create"); mntmCreate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileManager.create(p); } }); mnFile.add(mntmCreate); JMenuItem mntmSave = new JMenuItem("Save"); mnFile.add(mntmSave); JMenuItem mntmLoad = new JMenuItem("Load"); mnFile.add(mntmLoad); JMenuItem mntmExit = new JMenuItem("Exit (no save)"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mnFile.add(mntmExit); JMenuItem mntmLogin = new JMenuItem("Login"); mntmLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { FileManager.load(p); } }); menuBar.add(mntmLogin); contentPane = new JPanel(); contentPane.setBackground(new Color(210, 105, 30)); contentPane.setForeground(Color.BLACK); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); input = new JTextField(); input.setForeground(new Color(0, 128, 128)); input.setFont(new Font("SansSerif", Font.BOLD, 12)); input.setBackground(new Color(128, 0, 0)); input.addKeyListener(new KeyAdapter() { [MENTION=15855]Over[/MENTION]ride public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ENTER) { text = input.getText(); textArea.append(">"+p.getUsername()+"> "+text+"\n"); input.setText(""); } } }); input.setBounds(10, 232, 236, 28); contentPane.add(input); input.setColumns(10); JLabel lblEnterCommandsHere = new JLabel("Enter Commands Here"); lblEnterCommandsHere.setBounds(60, 206, 135, 14); contentPane.add(lblEnterCommandsHere); JLabel label = new JLabel(""); label.setIcon(new ImageIcon(".\\resources\\pictures\\logo.png")); label.setBounds(256, 17, 168, 177); contentPane.add(label); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(p.getHp()); progressBar.setStringPainted(true); progressBar.setToolTipText("HP"); progressBar.setBounds(256, 206, 168, 14); contentPane.add(progressBar); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 17, 236, 177); contentPane.add(scrollPane); textArea = new JTextArea(); textArea.setBackground(Color.CYAN); textArea.setAutoscrolls(true); scrollPane.setViewportView(textArea); } } [/code] Some stuff is out of order because I was trying to fix it myself. I think I found a fix but when I try to send more text it wont send any. And when I click on "login" and login my GUI would freeze now. I don't know why it's doing that also, my load seems fine, but I'm thinking that since my method for sending text to my GUI doesn't work properly it freezes. [code] public static void load(Player p) { String username = JOptionPane.showInputDialog("Please enter your username"); if(username.length() == 0) { System.exit(0); } File f = new File(".\\data\\games\\"+username+".txt"); if(f.exists()) { JOptionPane.showMessageDialog(null, "The file exists! Obtaining information"); try { String username1 = ""; String password = ""; int hp; int rights; BufferedReader reader = new BufferedReader(new FileReader(f)); username1 = reader.readLine(); password = reader.readLine(); hp = Integer.parseInt(reader.readLine()); rights = Integer.parseInt(reader.readLine()); reader.close(); p.setUsername(username1); p.setPassword(password); p.setHp(hp); p.setRights(rights); String password1 = JOptionPane.showInputDialog("Please enter your password"); if(password1.equals(p.getPassword())) { Room.start(); } if(!password1.equals(p.getPassword())) { JOptionPane.showMessageDialog(null, "WRONG PASSWORD!", "Alert", JOptionPane.ERROR_MESSAGE); } } catch(IOException ioe) { ioe.printStackTrace(); } } }[/code]
  23. Nvm, I thought I fixed it but I didn't. I'm just going to assume that JTextArea's cannot be updated by methods?
×