Results 1 to 6 of 6
- 12-08-2011, 09:04 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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()); } } }
- 12-09-2011, 05:02 AM #2
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-12-2011, 08:16 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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
007Last edited by 0070071; 12-12-2011 at 08:20 PM.
- 12-13-2011, 05:34 PM #4
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
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-17-2012, 06:31 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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
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? Thanksthe API for JOptionPane
007Last edited by 0070071; 01-17-2012 at 06:38 PM.
- 01-18-2012, 05:56 AM #6
Re: My code doesn't work! Pane.showOptionDialog()
I mean the API for JOptionPane
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Jar doesn't work
By mad72584 in forum New To JavaReplies: 35Last Post: 08-07-2011, 05:22 PM -
why this doesn't work?
By hitesh_public in forum New To JavaReplies: 5Last Post: 08-09-2010, 08:07 AM -
Repaint calling Statement Doesn't Work in my code ?
By nitin_daviet88 in forum CLDC and MIDPReplies: 2Last Post: 07-24-2010, 03:09 PM -
This code doesn't work. Why? thanks.
By seanzhang in forum New To JavaReplies: 10Last Post: 07-09-2010, 05:53 AM -
Why doesn't this work?
By Corder10 in forum New To JavaReplies: 1Last Post: 07-04-2009, 10:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks