Newbie compiler help using javax.swing class

current java ver java version "1.5.0_02"
error msg
[error]
C:\Documents and Settings\Neil\Desktop\Java>javac neiltest2.java
neiltest2.java:12: package javax does not exist
import javax.swing;
^
neiltest2.java:28: cannot resolve symbol
symbol : variable JOptionPane
location: class neiltest2
JOptionPane.showMessageDialog(null, "The total is " + intSum);
^
2 errors
[error]
* neiltest2.java
* Created on 02 June 2005, 19:02
* @author  Neil
* @version
import javax.swing;
public class neiltest2 {
    /** Creates new neiltest2 */
    public neiltest2() {
    * @param args the command line arguments
    public static void main (String args[]) {
        int intSum;
        intSum = 14+35;
        JOptionPane.showMessageDialog(null, "The total is " + intSum);
        System.exit(0);
}TIA
Neil

Use either
import javax.swing.JOptionPanel;
or
import javax.swing.*;
� {�                                                                                                                                                                               

Similar Messages

  • Help ! inaccurate time recorded using javax.swing.timer

    Hi All,
    I am currently trying to write a stopwatch for timing application events such as loggon, save, exit ... for this I have created a simple Swing GUI and I am using the javax.swing.timer and updating a the time on a Jlabel. The trouble that I am having is that the time is out by up to 20 seconds over a 10 mins. Is there any way to get a more accruate time ?? The code that I am using is attached below.
    private Timer run = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    timeTaken.setText("<html><font size = 5><b>" + (df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds++)) + "</b></font><html>");
    receordedTimeValue = ((df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds)));
    if (timeSeconds == 60) {
    timeMins++;
    timeSeconds = 0;
    if (timeMins == 60) {
    timeHours++;
    timeMins = 0;

    To get more accurate time you should use the System.currentTimeMillis() method.
    Try this code :
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CountUpLabel extends JLabel{
         javax.swing.Timer timer;
         long startTime, count;
         public CountUpLabel() {
              super(" ", SwingConstants.CENTER);
              timer = new javax.swing.Timer(500, new ActionListener() { // less than or equal to 1000 (1000, 500, 250,200,100) 
                   public void actionPerformed(ActionEvent event) {
                        if (startTime == -1) {          
                             count = 0;               
                             startTime = System.currentTimeMillis();
                        else {
                             count = System.currentTimeMillis()-startTime;
                        setText(getStringTime(count));
         private static final String getStringTime(long millis) {
              int seconds = (int)(millis/1000);
              int minutes = (int)(seconds/60);
              int hours = (int)(minutes/60);
              minutes -= hours*60;
              seconds -= (hours*3600)+(minutes*60);
              return(((hours<10)?"0"+hours:""+hours)+":"+((minutes<10)?"0"+minutes:""+minutes)+":"+((seconds<10)?"0"+seconds:""+seconds));
         public void start() {
              startTime = -1;
              timer.setInitialDelay(0);
              timer.start();
         public long stop() {
              timer.stop();
              return(count);
         public static void main(String[] args) {
              JFrame frame = new JFrame("Countdown");
              CountUpLabel countUp = new CountUpLabel();
              frame.getContentPane().add(countUp, BorderLayout.CENTER);
              frame.setBounds(200,200,200,100);
              frame.setVisible(true);
              countUp.start();
    Denis

  • Unable to Decrypt the data properly using javax.crypto class and SunJCE

    Hello all,
    I am not new to Java but new to this forums
    but and JCE and i wanted to write a program that Encrypts a file and also another program that decrypts it. As far Encryption is concerned i have been successful but When it comes to Decryption things aren't looking bright i have some or the other Problem with it. plz help me out .
    Here is the Code for my Programs
    Encryption
    Code:
    import java.io.*;
    import javax.crypto.*;
    import javax.crypto.spec.SecretKeySpec;
    import java.security.*;
    import javax.swing.*;
    class MyJCE
    public static void main(String args[])throws Exception
    Provider sunjce = new com.sun.crypto.provider.SunJCE();
    Security.addProvider(sunjce);
    JFileChooser jfc = new JFileChooser();
    int selection= jfc.showOpenDialog(null);
    if(selection==JFileChooser.APPROVE_OPTION)
    FileInputStream fis = new FileInputStream(jfc.getSelectedFile());
    System.out.println("Selected file " + jfc.getSelectedFile());
    try{
    KeyGenerator kg = KeyGenerator.getInstance("DESede");
    SecretKey key= kg.generateKey();
    byte[] mkey=key.getEncoded();
    System.out.println(key);
    SecretKeySpec skey = new SecretKeySpec(mkey, "DESede");
    Cipher cipher=Cipher.getInstance("DESede/ECB/NoPadding");
    cipher.init(Cipher.ENCRYPT_MODE,skey);
    byte[] data= new byte[fis.available()];
    //reading the file into data byte array
    byte[] result= cipher.update(data);
    byte[] enc= new byte [fis.read(result)];
    System.out.println("Encrypted =" + result);
    File fi= new File("/home/srikar/Encrypted");
    FileOutputStream fos= new FileOutputStream(fi);
    fos.write(enc);
    fos.close();
    byte[] encodedSpeckey = skey.getEncoded();
    FileOutputStream ks= new FileOutputStream("./key.txt");
    ks.write(encodedSpeckey);
    System.out.println("Key written to a file");
    }//try
    catch(Exception ex)
    ex.printStackTrace();
    }//catch
    }This Creates a Encrypted File. and a Encrypted key.txt
    Code:
    import java.io.*;
    import javax.crypto.*;
    import javax.crypto.spec.SecretKeySpec;
    import java.security.*;
    import javax.swing.*;
    class Decrypt
    public static void main(String[] args)
    try
    JFileChooser jfc = new JFileChooser();
    int selection= jfc.showOpenDialog(null);
    if(selection==JFileChooser.APPROVE_OPTION)
    FileInputStream fis = new FileInputStream(jfc.getSelectedFile());
    System.out.println("Selected file " + jfc.getSelectedFile());
    //Read from the Encrypted Data
    int ll= (int)jfc.getSelectedFile().length();
    byte[] buffer = new byte[ll];
    int bytesRead=fis.read(buffer);
    byte[] data= new byte[bytesRead];
    System.arraycopy(buffer,0,data,0,bytesRead);
    //Read the Cipher Settings
    FileInputStream rkey= new FileInputStream("./key.txt");
    bytesRead = rkey.read(buffer);
    byte[] encodedKeySpec=new byte[bytesRead];
    System.arraycopy(buffer,0,encodedKeySpec,0,bytesRead);
    //Recreate the Secret Symmetric Key
    SecretKeySpec skeySpec= new SecretKeySpec(encodedKeySpec,"DESede");
    //create the cipher for Decrypting
    Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE,skeySpec);
    byte[] decrypted= cipher.update(data);
    FileOutputStream fos= new FileOutputStream("/home/srikar/Decrypted");
    fos.write(decrypted);
    }//if
    }//try
    catch(Exception e)
    e.printStackTrace();
    }//catch
    }//main
    }//classthis Decrypt.java is expected to decrypt the above encrypted file but this simply creates a plaintext file of the same size as the Encrypted file but its contents are unreadable.
    Or I endup with Exceptions like BadPadding or IllegalBlockSize Exception if i use any other Algorithm .
    Please help out
    thanx in advance

    Srikar2871 wrote:
    Well thanx for ur reply but
    As i said there are No issues with ENCRYPTION and am getting an Encrypted file exactly of the same size as that of the original file and NOT as null bytes and Even am able to get a Decrypted file of again the same size of the Encrypted File but this time that data inside is in unreadable format.I ran your code EXACTLY* as posted and the contents of the file when viewed in a Hex editor was
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00So unless you are running different code to what you have posted, your file will look the same.
    Cheers,
    Shane

  • Changing javax.swing class

    Hello,
         I am an experienced programmer new to java. I found a solution to a problem I am having with BoxLayout in the bug database. The solution makes a change to the SizeRequirements class in javax.swing. I found the source for the class and have recompiled it. But the recompiled class is not being picked up. What do I do next? The classes all seem to be in a jar file although I can't find one with SizeRequirements. Is there the concept of linking in Java or do I just need to put the class in the right path location?
    Thanks,
    Lori

    ...file although I can't find one with SizeRequirements. If you can't find it then you might want to go back to the drawing board since you probably have a different java version.
    I don't believe standard class files are loaded via the classpath.
    This command line option is taken from the javadocs
    -Xbootclasspath/p:path
    Specify a semicolon-separated path of directires, JAR archives, and ZIP archives to prepend in front of the default bootstrap class path. Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license.
    The last sentence is important.

  • How to create a calculator by using javax swing

    I try to us Javax swing make some buttons like 0 - 9 then input some numbers by using those number like a calculator. But I only can get numbers no more than 9.
    Please help me.

    How do you store the number the user enters? If it's in a string and the previous value was eg "1" and the user enters "2" you get "12" with a simple concatenation: val += input.
    OTOH, if you work with doubles and the previous value was 1.0 and the user enters 2.0 by pressing the button you get 12.0 by multiplying 1.0 with 10 and adding 2.0: val = 10*val + input.

  • How can I use java swing class in JSP page design

    I am a new developer in Java server pages. I want to use layout managers available in java swing classes to design the page. Can any body suggest me a way to do this.Is it possible if I do it with servelets.

    So, you want to use layout managers within your JSPs?
    The immediate answer is that "it isn't a good idea". The more considered answer is "tell us what you're up to".
    Are you coding all presentation within a traditional JSP? That is, HTML, customer or library tags and/java scriptlets?
    Or are you building your HTML within your servlets and sending that back to the browser?
    If the first, then you are probably better off either using explicit HTML tables (or the equivalent custom tags) or finding a library that you can use.
    If the second, you can write classes similar to the Swing layout managers that end up being a fancy way of putting elements into an HTML table. We have exactly that in my current environment. I wouldn't recommend rolling your own and I'd tend to leave all that presentation stuff to the JSP.
    In any case, you can't really use the Swing layout managers as they are for an entirely different pradigm.

  • Help..Javax.swing

    I need to find where SPECIFIC I can download this package.I'm trying to import this for a combo box....
    import javac.swing.*;
    and I can't find the right package that contains it. Any information would be appreciated. Thanks!!

    it should be:
    import javax.swing.*;

  • How to use javax.swing in Pocket PC

    I want to write an application with Swing GUI interface and run on my Pocket PC (iPAQ H3870). It is possible?
    I am using Jeode VM now.
    Thanks.

    I ran across a product called CrEme, that claims to support swing 1.1.1. I used the evaluation and it seemed to work much like Jeode. I never tried working with swing with it. Here is a link with information about CrEme:
    http://www.nsicom.com/news/pressrelShow.asp?ID=304&CategoryID=1

  • Using of javax.swing.text package

    Where can I find any resources devoted to using javax.swing.text package?

    At the end of the API documentation for that package you may notice this:
    <quote>
    Related Documentation
    For overviews, tutorials, examples, guides, and tool documentation, please see:
    Using Text Components, a section in The Java Tutorial.
    </quote>

  • Problem Loading an Image with javax Swing from a JApplet

    First of all, i use JCreator as java creater and have the newest version of java sdk version.
    Now i need to load an image from the harddrive on which the JApplet is located. I need to do this from inside the JApplet. I have put my pictures in a map 'images' which is located in the same directory as the classes + htm file. It works from inside JCreator, but as soon as i open the normal htm it just WON'T load that image (grmbl).
    Here is my code for loading the image:
    public BufferedImage loadImage (String filename, int transparency)
         Image image;
         if (app)
              image = Toolkit.getDefaultToolkit().getImage(("./images/"+filename));
         else
              String location = "";
              location = "./images/"+filename;
              image = Toolkit.getDefaultToolkit().getImage(location);
         MediaTracker mediaTracker = new MediaTracker(new Container());
         mediaTracker.addImage(image, 0);
         try
              mediaTracker.waitForID(0);
         catch (Exception e)
    Could anybody help me out here??
    I tried a url already using getCodeBase() or getDocumentBase() but that gives an error because it cannot find those if using a JApplet.

    Why don't you use javax.swing.ImageIcon? If you already have a flag telling if it's an application or applet, use the getDocumentBase() to base the URL in the applet part only.

  • Javax.swing.JTextPane - COLOR Problem

    Hi
    I am using javax.swing.JTextPane object to display text recieved from two servers.
    How can I make messages recieved from Server 1 to be in RED and while from Server 2
    to be in Green? i.e. the window should look...
    (red) Server 1 says ta ta
    (green) Server 2 says Hello
    My code looks....
    javax.swing.JTextPane WINDOW;
    String message1 = connection1.getMessage();
    ..........// What code should I put here??? to make this message look RED??
    ..........// Color of previous text should remain as it is...
    WINDOW.setText(WINDOW.getText() + message1);An Example would be highly appreciated.
    Regards
    Fahad

    Hi,
    that is the wrong way - try this method in your JTextPane subclass
    public void appendText(String s,Color col) {
    StyledDocument sd = getStyledDocument();
    SimpleAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForground(attr,col);
    try { sd.insertString(sd.getLength(),s,attr); }
    catch (BadLocationException e) {}
    } // end of methodand use it in your code like that
    WINDOW.appendText(message1,Color.red);
    hope that helps
    greetings Marsian

  • Javax.swing.JFileChooser -- open button change current directory... Why?

    Hello community.
    I use javax.swing.JFileChooser class. After press open button, JFileChooser change current directory. Why?
    I was not find in documentation about changing curret directiry by JFileChooser. Take me please reference to doc for understanding this effect.
    Thank you.

    This is my code:
    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {                                             
    // TODO add your handling code here:
    // label1.setText("3: "+evt.);
    // label1.setText("3: ");
    label1.setText(evt.getActionCommand());
    System.out.println(evt.getActionCommand());
    if (evt.getActionCommand().startsWith("Approve")){
    label1.setText("You push Open key");
    System.out.println(jFileChooser1.getCurrentDirectory().getPath());
    label1.setText(jFileChooser1.getCurrentDirectory().getPath());
    }else{
    label1.setText("You push Close key");
    I not add method for change current directory. But after press on open button javax.swing.JFileChooser class was change current directory.

  • Can't use import javax.swing.RowFilter; in javafx

    Dear all,
    I'm a question for you.
    I developed a javafx application in which I use also swing dialog and swingx libraries.
    The question is I can't use jtable filter of java jdf 1.6
    That is when I try to add in my netbeans javafx project
    import javax.swing.RowFilter;
    it says me it's not correct library
    If I create a java swing application I can add this include.
    Why it?
    I edited netbeans conf to set javafx sdk to javafx lib I downloaded (whole sdk), not that one with netbeans, but nothing.
    It seems like I can't use this import in javafx application.
    Is it posbbile?
    Please help me

    The reason you cannot use it is because javax.swing.RowFilter was introduced in Java 1.6 . Netbeans compiles JavaFX to work with Java 1.5, which does not have the class in question.
    I have gotten around this by going to the properties->Libraries->Add JAR/Folder menu and included the jre/lib/rt.jar file from the jre directly into my project.
    Someone else posted a similar solution and more detailed explanation here: http://steveonjava.com/hacking-javafx-10-to-use-java-16-features/

  • Where is javax.swing.GroupLayout Class....?

    In the Java 6 Doc I am getting the information about javax.swing.GroupLayout class. But I cpuld not find the class in Jar.
    Am I missing something?
    It will be appriciated If you help me to finding the Jar file for this class.
    Thanks.

    Thanks for help.
    I have got it. As I am using beta version of Java6 in which that class was missing. In the latest version of JDK , I have found that class.

  • Why can i not get the class javax/swing/UImanager from installanywhere??

    I use Installanywhere to pack my program,but when i double-click the short-cut,it says no class found :javax/swing/UImanage.
    anybody can tell what happened?
    thanks.

    who can help me ? none want to help me.

Maybe you are looking for