Results 1 to 6 of 6
  1. #1
    0070071 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Unhappy My code doesn't work! Pane.showOptionDialog()

    Hi

    I've been working on code for ages, but for some reason suddenly i get this error:

    Launcherv2.java:103: showOptionDialog(java.awt.Component,java.lang.Obje ct,java.l
    ang.String,int,int,javax.swing.Icon,java.lang.Obje ct[],java.lang.Object) in java
    x.swing.JOptionPane cannot be applied to (java.lang.String,int)
    int download = JOptionPane.showOptionDialog("Wou
    ld you like to update/download?",JOptionPane.YES_NO_OPTION);
    ^
    Launcherv2.java:147: showOptionDialog(java.awt.Component,java.lang.Obje ct,java.l
    ang.String,int,int,javax.swing.Icon,java.lang.Obje ct[],java.lang.Object) in java
    x.swing.JOptionPane cannot be applied to (java.lang.String,int)
    int run = JOptionPane.showOptionDialog("
    Would you like to run Ducklings Online?",JOptionPane.YES_NO_OPTION);
    ^
    2 errors


    this is my code:
    Java Code:
    import javax.swing.*;
    import java.io.*;
    import java.io.File;
    import java.net.*;
    
    
    
    class Launcherv2{
    	public static void main(String [] args){
    	
    	
    		URL url; //represents the location of the file we want to dl.
    		URLConnection con;  // represents a connection to the url we want to dl.
    		DataInputStream dis;  // input stream that will read data from the file.
    		FileOutputStream fos; //used to write data from inut stream to file.
    		byte[] fileData;  //byte aray used to hold data from downloaded file.
    
    		
    		String s = null;
    		
    	
    		try{
    		
    		
    			File file = new File("version.txt");
    
    
    
    
    
    
    
    
    
    			url = new URL("http://quackersgames.co.uk/images/DucklingsOnline/version.txt");
    			con = url.openConnection(); // open the url connection.
    			dis = new DataInputStream(con.getInputStream()); // get a data stream from the url connection.
    			fileData = new byte[con.getContentLength()]; // determine how many byes the file size is and make array big enough to hold the data
    			for (int x = 0; x < fileData.length; x++) { // fill byte array with bytes from the data input stream
    				fileData[x] = dis.readByte();
    			}
    			dis.close(); // close the data input stream
    			fos = new FileOutputStream(new File("versiond.txt"));  //create an object representing the file we want to save
    			fos.write(fileData);  // write out the file we want to save.
    			fos.close(); // close the output stream writer
    
    
    
    
    
    
    
    
    
    
    
    
    
    			
    	
    			File verd = new File("versiond.txt");
    			FileReader verdFil = new FileReader(verd);
    			BufferedReader ind = new BufferedReader(verdFil);
    			int [] verdi = new int [1];
    			String sdi =ind.readLine();
    			while(sdi!=null) {
    				int i = 0;
    				verdi[i] = Integer.parseInt(sdi);
    				//System.out.println(verdi[i]);
    				sdi = ind.readLine();
    			}
    			ind.close();
    
    
    
    
    			
    
    			File ver = new File("version.txt");
    			FileReader verFil = new FileReader(ver);
    			BufferedReader in = new BufferedReader(verFil);
    			int [] veri = new int [1];
    			String si =in.readLine();
    			while(si!=null) {
    				int i = 0;
    				veri[i] = Integer.parseInt(si);
    				//System.out.println(veri[i]);
    				si = in.readLine();
    			}
    			in.close();
    
    
    
    
    
    
    
    
    			
    			
    			if(!file.exists() || veri[0] != verdi[0]){
    			
    				int download = JOptionPane.showOptionDialog("Would you like to update/download?",JOptionPane.YES_NO_OPTION);
    				
    				if(download == JOptionPane.NO_OPTION){
    					System.exit(0);
    				}
    				if(download == JOptionPane.CLOSED_OPTION){
    					System.exit(0);
    				}
    			
    				if(download == JOptionPane.YES_OPTION){
    				
    				
    					url = new URL("http://quackersgames.co.uk/images/DucklingsOnline/DucklingsOnline.exe");
    					con = url.openConnection(); // open the url connection.
    					dis = new DataInputStream(con.getInputStream()); // get a data stream from the url connection.
    					fileData = new byte[con.getContentLength()]; // determine how many byes the file size is and make array big enough to hold the data
    					for (int x = 0; x < fileData.length; x++) { // fill byte array with bytes from the data input stream
    						fileData[x] = dis.readByte();
    					}
    					dis.close(); // close the data input stream
    					fos = new FileOutputStream(new File("DucklingsOnline.exe"));  //create an object representing the file we want to save
    					fos.write(fileData);  // write out the file we want to save.
    					fos.close(); // close the output stream writer
    					
    
    
    
    
    
    
    					url = new URL("http://quackersgames.co.uk/images/DucklingsOnline/version.txt");
    					con = url.openConnection(); // open the url connection.
    					dis = new DataInputStream(con.getInputStream()); // get a data stream from the url connection.
    					fileData = new byte[con.getContentLength()]; // determine how many byes the file size is and make array big enough to hold the data
    					for (int x = 0; x < fileData.length; x++) { // fill byte array with bytes from the data input stream
    						fileData[x] = dis.readByte();
    					}
    					dis.close(); // close the data input stream
    					fos = new FileOutputStream(new File("version.txt"));  //create an object representing the file we want to save
    					fos.write(fileData);  // write out the file we want to save.
    					fos.close(); // close the output stream writer
    
    
    
    					int run = JOptionPane.showOptionDialog("Would you like to run Ducklings Online?",JOptionPane.YES_NO_OPTION);
    				
    					if(run == JOptionPane.YES_OPTION){
    					Process p = Runtime.getRuntime().exec("C:\\Program Files\\Ducklings Online\\ducklings-online.exe");
    					}
    
    				}
    
    			}
    			else{
    				
    				
    				Process p = Runtime.getRuntime().exec("C:\\Program Files\\Ducklings Online\\ducklings-online.exe");
    				
    				
    				
    					
    			}
    			
    			
    		
    		
    		
    		}catch (Exception e){
    			System.err.println("Error: " + e.getMessage());
    		}
    	}
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: My code doesn't work! Pane.showOptionDialog()

    Your problem is with a single JOptionPane method call and you post a couple of hundred lines of network communication stuff, including absurd amounts of vertical whitespace? I nearly didn't bother to even take a look.

    Anyways. Do you know how to find and read an API? Have you checked the API for JOptionPane#showOptionDialog? Do you see any overload that takes two parameters?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    0070071 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: My code doesn't work! Pane.showOptionDialog()

    Sorry, but I use the the whitespace to separate areas of code, which is what I incorrectly thought everyone else did, thanks for the help, I'll check it out. Sorry for asking but what do you mean by
    overload that takes two parameters
    ?

    EDIT:
    Also how do I edit the original post, there isn't an 'edit' button like for this one

    /EDIT

    EDIT2:
    cool sig
    /EDIT2

    Thanks
    007
    Last edited by 0070071; 12-12-2011 at 09:20 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: My code doesn't work! Pane.showOptionDialog()

    OK let's take it one thing at a time.

    Do you know where to find the API for JOptionPane?

    As for acceptable amounts of vertical whitespace and other formatting niceties, I recommend you go through Code Conventions for the Java(TM) Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    0070071 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: My code doesn't work! Pane.showOptionDialog()

    Sorry, I realise now that there is no need for such meaningless confusing amounts of whitespace, and have just read the whitespace code conventions page. Any future help that I ask for will be properly whitespaced. Also, what do you mean by
    the API for JOptionPane
    unless you mean javax.swing.JOptionPane , I used the * wildcard, because I thought the error was coming from a misspelling or something like that. Thanks for your help, I'm a noob/newbie at java so I don't know that much. And how do I edit the original post to get rid of the whitespace? Thanks

    007
    Last edited by 0070071; 01-17-2012 at 07:38 PM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: My code doesn't work! Pane.showOptionDialog()

    Quote Originally Posted by 0070071 View Post
    Also, what do you mean by
    the API for JOptionPane
    I mean the API for JOptionPane

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 06:22 PM
  2. why this doesn't work?
    By hitesh_public in forum New To Java
    Replies: 5
    Last Post: 08-09-2010, 09:07 AM
  3. Repaint calling Statement Doesn't Work in my code ?
    By nitin_daviet88 in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-24-2010, 04:09 PM
  4. This code doesn't work. Why? thanks.
    By seanzhang in forum New To Java
    Replies: 10
    Last Post: 07-09-2010, 06:53 AM
  5. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 11:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •