Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: none of my friends can run my simple game launcher

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default none of my friends can run my simple game launcher

    Hi. i am having a problem. i made a program that downloads and runs the game(only basic frame for now), but when my friends try to open it. it simply wont open and it works on my computer. no errorrs no nothing.
     
    import java.awt.Component;
    import javax.swing.JFrame;
    public class main extends JFrame
    {
     
    public main(){
     
     
    }
     
     
        public static final void main(String[] args) throws Exception
        {
        new main2();
     
     
        }
    }
     
     
     
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JPanel;
     
    public class JPanelWithBackground extends JPanel {
     
      private Image backgroundImage,exit,start;
     
      // Some code to initialize the background image.
      // Here, we use the constructor to load the image. This
      // can vary depending on the use case of the panel.
      public JPanelWithBackground(String fileName) throws IOException {
        backgroundImage = ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\hg.png"));
        exit = ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\exit1.png"));
        start = ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\start.png"));
      }
     
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
     
        // Draw the background image.
        g.drawImage(backgroundImage, 0, 0,500,300, this);
        g.drawImage(exit,450,0,50,50,this);
        g.drawImage(start,260,100,90,30,this);
      }
    }
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JProgressBar;
    import javax.swing.JWindow;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author User
     */
    class main2 extends JWindow implements ActionListener{
    public BufferedImage start1,hg,exit1;
    public JButton exit,start;
        private Thread thread;
     
     
     
        public void display()
        {
     
            setBounds(400,400,500,300);
            setVisible(true);
     
     
        }
     
           private void load() {
     
     
          try {
     
     
             start1 =  ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\start.png"));
             hg =  ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\hg.png"));
             exit1 =  ImageIO.read(new File("C:\\Users\\User\\Desktop\\titles\\exit.png"));
     
          } catch(IOException e) {
             System.out.println("failed");
          }
             }
     
     
     
     
     
        public main2() {
        try {
            try {
                getContentPane().add(new JPanelWithBackground(""));
                load();
                display();
     
                requestFocusInWindow();
                this.setFocusable(true);
                exit = new JButton("exit");
                start = new JButton("start");
                start.addActionListener(this);
                start.setFocusable(true);
                JProgressBar current = new JProgressBar(0, 100);
                Container c = getContentPane();
                c.setLayout(null);
                c.add(current);
                c.add(start);
                c.add(exit);
                start.setBounds(260,100,90,30);
                exit.setIcon(new ImageIcon(exit1));
                exit.setBounds(450, 0, 30, 30);
                exit.setBackground(null);
                exit.setBorder(null);
                exit.setBorderPainted(false);
                exit.setContentAreaFilled(false);
                exit.setFocusPainted(false); 
                exit.setVisible(true);
                exit.addActionListener(this);
                setVisible(true);
                start.setIcon(new ImageIcon(start1));
                String site="http://host.bugs3.com/hg/update.zip";
                if(!new File("C://The Hunger Games").exists()){
                  new File("C://The Hunger Games").mkdir();
              } else {
     
                }
     
                String folder="C://The Hunger Games//update.zip";
                JFrame frm=new JFrame();
                current.setSize(50,50);
                // current.setValue(0);
                current.setBounds(50, 50, 350, 25);
                current.setStringPainted(true);
                current.setBackground(Color.green);
                current.setForeground(Color.red);
                try {
                    URL url=new URL(site);
                    HttpURLConnection connection =
                        (HttpURLConnection) url.openConnection();
                    int filesize = connection.getContentLength();
                    float totalDataRead=0;
                        java.io.BufferedInputStream in = new java.io.BufferedInputStream(connection.getInputStream());
                        java.io.FileOutputStream fos = new java.io.FileOutputStream(folder);
                        java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
                        byte[] data = new byte[1024];
                        int i=0;
                        while((i=in.read(data,0,1024))>=0)
                        {
                        totalDataRead=totalDataRead+i;
                        bout.write(data,0,i);
                        float Percent=(totalDataRead*100)/filesize;
                        current.setValue((int)Percent);
                        }  
                        bout.close();
                        in.close();
                }
                catch(Exception e)
                {
                     javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
                             null,e.getMessage(), "Error",
                             javax.swing.JOptionPane.DEFAULT_OPTION);
                }
            }
            catch(IOException ex)
            {
                 Logger.getLogger(main2.class.getName()).log(
                         Level.SEVERE, null, ex);
            }
         unzipFile("C://The Hunger Games//update.zip");
        } catch (IOException ex) {
            Logger.getLogger(main2.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    public void unzipFile(String filePath) throws IOException{
     
            FileInputStream fis = null;
            ZipInputStream zipIs = null;
            ZipEntry zEntry = null;
            try {
                fis = new FileInputStream(filePath);
                zipIs = new ZipInputStream(new BufferedInputStream(fis));
                while((zEntry = zipIs.getNextEntry()) != null){
                    try{
                        byte[] tmp = new byte[4*1024];
                        FileOutputStream fos = null;
                        String opFilePath = "C://The Hunger Games//"+zEntry.getName();
                        System.out.println("Extracting file to "+opFilePath);
                        fos = new FileOutputStream(opFilePath);
                        int size = 0;
                        while((size = zipIs.read(tmp)) != -1){
                            fos.write(tmp, 0 , size);
                        }
                        fos.flush();
                        fos.close();
                    } catch(Exception ex){
     
                    }
                }
                zipIs.close();
            } catch (FileNotFoundException e) {
     
                e.printStackTrace();
            } 
        }
     
     
        @Override
        public void actionPerformed(ActionEvent e) {
        if(e.getSource() == exit) {
            System.exit(0);
        }
        if(e.getSource() == start) {
            dispose();
            try {
            Process ps=Runtime.getRuntime().exec(new String[]{"java","-jar","C://The Hunger Games//HungerGamesClient.jar"});
            ps.waitFor();
            java.io.InputStream is=ps.getInputStream();
            byte b[]=new byte[is.available()];
            is.read(b,0,b.length);
            System.out.println(new String(b));
            } catch (IOException ex) {
                Logger.getLogger(main2.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(main2.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        }
     
    }
    Attached Files Attached Files


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: none of my friends can run my simple game launcher

    Can you post the code that isn't working (preferably as an SSCCE)? How are your friends trying to run your code? What error do they see?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: none of my friends can run my simple game launcher

    What files do your friends have and how are they executing the java program?

    Have them open a command prompt window and execute your code there. Error messages should be shown on the command prompt window. Copy the contents of the window and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: none of my friends can run my simple game launcher

    Quote Originally Posted by KevinWorkman View Post
    Can you post the code that isn't working (preferably as an SSCCE)? How are your friends trying to run your code? What error do they see?
    i already posted the code. my friends are running it as a .jar

    --- Update ---

    Quote Originally Posted by Norm View Post
    What files do your friends have and how are they executing the java program?

    Have them open a command prompt window and execute your code there. Error messages should be shown on the command prompt window. Copy the contents of the window and paste it here.
    They dont have images of this launcher but it works without them for me. My friends are offline now, but i remember that when i tryed to tell them to run it trough command prompt, it thrown error about file download and extraction and there was something else but i dont remember what. Whye could this happen?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: none of my friends can run my simple game launcher

    Try using the command prompt window to see what errors there are.
    Change to the folder with the jar file and enter:
    java -jar THEJARFILENAME.jar

    Copy the contents of the window and paste it here.

    Some problems I see:
    the code is expecting image files to exist. All files the program uses should be included in the jar file.
    There are empty catch blocks. All catch blocks should call the printStackTrace() method.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: none of my friends can run my simple game launcher

    Quote Originally Posted by deivisxm View Post
    i already posted the code. my friends are running it as a .jar[COLOR="Silver"]
    The code you posted doesn't seem complete like an SSCCE should- for example, I don't see a main() method.

    Quote Originally Posted by deivisxm View Post
    They dont have images of this launcher but it works without them for me. My friends are offline now, but i remember that when i tryed to tell them to run it trough command prompt, it thrown error about file download and extraction and there was something else but i dont remember what. Whye could this happen?
    Without seeing an SSCCE it's going to be pretty hard to tell you what's going on, and without knowing the specific error it's going to be impossible. It seems strange that your program would work without the required images (which should probably just be packaged into the jar anyway), but you might be doing something wonky with catching Exceptions. Again, an SSCCE would go a long way to helping us answer your question.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: none of my friends can run my simple game launcher

    sorry. edited. first file is main

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: none of my friends can run my simple game launcher

    Some comments:
    why have a separate class (main) that extends JFrame and that has a main() method that does nothing with the class it is in? The main() method should be in the class it is starting.
    The class names don't follow the java naming conventions: class names should start with a capitalized letter.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: none of my friends can run my simple game launcher

    my codes usually have too much writen in them.. but can this couse my problem?

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: none of my friends can run my simple game launcher

    I second everything Norm said.

    I'm not sure what you mean when you ask if having too much code can cause a problem: the short answer is no. The longer answer is that it seems like you don't fully understand everything your code is doing (such as the issues Norm pointed out), and that can definitely lead to problems.

    Creating an SSCCE eliminates all the extra and boils the problem down to the specific error you're seeing. The best way to create an SSCCE is to start a new project from scratch and only add the bare minimum required to see the error. If your friends are getting an error on a specific line, the best thing to do is create a program that executes only that line (with hard-coded values where needed).
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: none of my friends can run my simple game launcher

    We need to see the full text of the error message to know what the problem is.

    The program requires lots of files be on the user's disk. Putting all of them into the jar file will reduce the chances of problems.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: none of my friends can run my simple game launcher

    So.. If there are no image files, launcher wont even show jwindow?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: none of my friends can run my simple game launcher

    It depends on how the program is written.
    Move the images, do a test and see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: none of my friends can run my simple game launcher

    Ok thanks, the problem was image locations

Similar Threads

  1. Launcher Downloads, but wont extract.
    By MikeTheShadowSage in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2013, 09:29 AM
  2. Replies: 12
    Last Post: May 8th, 2012, 05:22 PM
  3. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM
  4. Can't run Game of Life programm
    By cutekill0 in forum What's Wrong With My Code?
    Replies: 24
    Last Post: September 13th, 2011, 08:30 AM
  5. [SOLVED] Turn Based Game run by Commands
    By EggoH1992 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 11th, 2011, 10:23 AM