Problem compiling with Swing

I am new to java.
I have recently installed jdk-1.3.1_01 and am able to compile and run basic java programs. However, when trying to compile HelloWorldSwing.java, I get the following error:
HelloWorldSwing.java:6: error:Cannot find class "JFrame" [JLS 8]
Is this a classpath problem? Please help!

yes, I'm sure the code is right. What is strange is that when I first installed jdk, I was able to compile and run the swing program. Once I closed the terminal, though, and opened a new one, I was unable to compile. I'm using Linux Mandrake 8.1. Any ideas?

Similar Messages

  • Problems compiling with packages

    Hi,
    I wonder if anyone could help me.
    I have had problems compiling using a package. I have altered the classpath in autoexec.bat with:
    SET CLASSPATH=%classpath%;C:\jdk1.3.1_02\classes;.
    the package class files are stored in C:\jdk1.3.1_02\classes\helliker\id3
    and I have imported the class with:
    import helliker.id3.*;
    I am getting the following error:
    C:\My Documents\Uni work\mp3 project\test\Driver.java:1: package helliker.id3 does not exist
    import helliker.id3.*;
    ^
    Can anybody help?
    Thanks,
    Dave

    Perhaps the version of Windows you are using does not use autoexec.bat. For example, in NT and XP, you set Classpath using ControlPanel/System/Advanced/Environment Variables.
    Perhaps there is a typo in your Classpath, for example an extra space.
    On a command line, try this:
    javac -classpath C:\jdk1.3.1_02\classes C:\My Documents\Uni work\mp3 project\test\Driver.java
    If that works, then definitely Classpath is not set as you think it is.

  • Problem compiling with IVParameterSpec

    I'm trying to build a password file that will be created by one program and read by a different one using CipherInput/OutputStreams. I believe that I need a repeatable key so that as I write the file, I can also read it.
    I'm trying to use cipher.init (Cipher.ENCRYPT_MODE, key, ivSpec) with ivSpec set to the same array of bytes in both my read and write routines. When I try to compile the write class, I get an error at my import statement for the IVParameterSpec.
    Line 78:   import javax.crypto.spec.IVParameterSpec;Error:
    [javac] C:\rat\jtim\src\com\baesystems\jtim\RemotePassword.java:78: cannot resolve symbol
    [javac] symbol : class IVParameterSpec
    [javac] location: package spec
    [javac] import javax.crypto.spec.IVParameterSpec;
    Do I need to load something else into the JDK to get IVParameterSpec? What could I be doing wrong?

    just a spelling mistake.
    javax.crypto.spec.IvParameterSpecThe "v" in Iv is the small V, not the capital V.
    Thanks. You'd think after 15 years of Unix, I'd be able to catch a case error.

  • Problem compiling with a  final static statement

    I'm trying to compile a code that i obtained from jad. The error is:
    MethodInvoke.java:269: illegal start of type
    ^
    At the final of the code i got:
    static final
    {                //here appear the problem
    try
    pool = new ObjectPool(com.test.wsp.main.MethodInvoke.class);
    catch(Exception exception)
    throw new ExceptionInInitializerError("could not initialize the worker pool, exception=" + com.tess.hometop.gateways
    .utils.Utils.parse(exception));
    Could anyone explain me which is the problem?
    Thanks

    I'm trying to compile a code that i obtained from jad. The error is:
    MethodInvoke.java:269: illegal start of type
    ^
    At the final of the code i got:
    static final
    {                //here appear the problem
    try
    pool = new ObjectPool(com.test.wsp.main.MethodInvoke.class);
    catch(Exception exception)
    throw new ExceptionInInitializerError("could not initialize the worker pool, exception=" + com.tess.hometop.gateways
    .utils.Utils.parse(exception));
    Could anyone explain me which is the problem?
    Thanks

  • SUNWspro iostream error while compiling with SunStudio 10

    We are getting the following error when we try to compile the C++ code using SunStudio 10 on Sun Solaris Sparc server.
    We made couple of changes in the source code 1) whereever we have stream.h we replaced it with iostream.h and 2) include fstream.h whereever required.
    Can anyone tell us where did it go wrong.
    + /opt/SUNWspro/bin/CC -g -O -DHAWK -mt -lclntsh -lsocket -lnsl -I/export/home/StandardComponents/SC/include -I../../mylib -I../../include -I/opt/SUNWspro/prod/include/CC/Cstd -I. -I- -D_TRACE_ -c collectDborMtoInfo.c
    "/opt/SUNWspro/prod/include/CC/Cstd/iostream.h", line 20: Error: Use ";" to terminate declarations.
    "/opt/SUNWspro/prod/include/CC/Cstd/iostream.h", line 20: Error: A declaration was expected instead of "'\n'".
    "/opt/SUNWspro/prod/include/CC/Cstd/iostream.h", line 20: Error: Use ";" to terminate declarations.
    "/opt/SUNWspro/prod/include/CC/Cstd/iostream.h", line 20: Error: A declaration was expected instead of "'\n'".
    4 Error(s) detected.

    Remove the -I directive that points into the compiler installation. You should not have have -I or -L options that point into the compiler installation area, into /usr/include, or into /usr/lib. The CC compiler driver knows where to find system headers and libraries, and in what order to search the directories. If you force a different search order, you can break something.
    If removing -I/opt/SUNWspro/prod/include/CC/Cstd does not fix the problem, compiling with -P or -E will show you the preprocessor output, and looking at the lines with the errors will usually show the source of the problem quickly.
    BTW, you should be aware that the ".h" form of the C++ headers, like <iostream.h> and <fstream.h>, is not standard. Using them is not portable, because not all C++ implementations provide them, and those that do often have different content.

  • Problem in compiling with -g option

    I am using forte5.1 compiler. While compiling my whole source code with -g option, for some of the files, the compilation is successfully but for some files I am getting en error as ">> Assertion (../link/dbg_stcomm.cc, line 271) while processing srsCallbacks.C at line 0. Error code 1. make:Fatal error". If I try to compile the whole source code without -g option my whole compilation is successfull. I have downloaded all the required patches for this. Previously I was using compiler 5.0 and I was not getting any error with -g option. Can u just tell me why am I facing this problem specifically with forte5.1 and not with 5.0. How can I resolve this problem so as to compile the whole source code with -g option?

    Hi,
    I think you will need patch:
    Patch-ID# 109490-01
    Synopsis: C++ 5.1: Patch for Forte Development 6 C++ compiler
    As it appears that you are hitting bug id # 4312608
    "Assertion: (../links/dbg_stcomm.cc, line 271)"
    Can you confirm whether you are having this patch by doing:
    "CC -V" or "showrev -p"
    Thanks,
    Gopinath.
    Sun - DTS.

  • Having problems compiling *.java with import javax.servlet.jsp......

    I've been trying to do the tutorials in a book titled Apache Jakarta-Tomcat as part of my introduction to JSP. I'm new to Java but do know the basics. I have on my machine Java 1.3, Java 1.4, Java FrameWorks 2.1 and Jython 2.1 on Win2000 Pro. So enough about my configuration. I have never worked with packages also.
    I downloaded the files from the books site due to the fact I make a lot of typos when hand coding Java (I've become a pretty good debugger of my own code). But everytime I go to compile the *.java I get error messages. So below you will find HelloTag.java and beneath that the error messages that are thrown when I try and compile it. I tested other bits of *.java and have had no problem compiling them. Is there a JSP module I'm missing?
    Am I doing something wrong or am I missing something from my configuration.
    Marijan Madunic
    package chapter2;
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspTagException;
    import javax.servlet.jsp.tagext.TagSupport;
    public class HelloTag extends TagSupport
    public void HelloTag() {
    // Method called when the closing hello tag is encountered
    public int doEndTag() throws JspException {
    try {
    // We use the pageContext to get a Writer
    // We then print the text string Hello
    pageContext.getOut().print("Hello");
    catch (Exception e) {
    throw new JspTagException(e.getMessage());
    // We want to return SKIP_BODY because this Tag does not support
    // a Tag Body
    return SKIP_BODY;
    public void release() {
    // Call the parent's release to release any resources
    // used by the parent tag.
    // This is just good practice for when you start creating
    // hierarchies of tags.
    super.release();
    D:\Java\JDK 1.3\bin>javac HelloTag.java
    HelloTag.java:3: cannot resolve symbol
    symbol : class JspException
    location: package jsp
    import javax.servlet.jsp.JspException;
    ^
    HelloTag.java:4: cannot resolve symbol
    symbol : class JspTagException
    location: package jsp
    import javax.servlet.jsp.JspTagException;
    ^
    HelloTag.java:5: cannot resolve symbol
    symbol : class TagSupport
    location: package tagext
    import javax.servlet.jsp.tagext.TagSupport;
    ^
    HelloTag.java:7: cannot resolve symbol
    symbol : class TagSupport
    location: class chapter2.HelloTag
    public class HelloTag extends TagSupport
    ^
    HelloTag.java:14: cannot resolve symbol
    symbol : class JspException
    location: class chapter2.HelloTag
    public int doEndTag() throws JspException {
    ^
    HelloTag.java:20: cannot resolve symbol
    symbol : variable pageContext
    location: class chapter2.HelloTag
    pageContext.getOut().print("Hello");
    ^
    HelloTag.java:24: cannot resolve symbol
    symbol : class JspTagException
    location: class chapter2.HelloTag
    throw new JspTagException(e.getMessage());
    ^
    HelloTag.java:28: cannot resolve symbol
    symbol : variable SKIP_BODY
    location: class chapter2.HelloTag
    return SKIP_BODY;
    ^
    HelloTag.java:37: cannot resolve symbol
    symbol : variable super
    location: class chapter2.HelloTag
    super.release();
    ^
    9 errors

    Well, it looks like you've not got the servlet development kit JAR on your classpath. I think it'll probably be called servlet.jar on your system. Add that to the classpath if it's not already there.
    Incidentally, you've bumped into one of the areas Java's slightly lenient - declaring a method that looks like a constructor:
    public HelloTag() { }
    public void HelloTag() { }The first is a constructor, the second is a normal method. I'm assuming you intended to have the former instead of the latter.
    Anyway, hope this helps.

  • Problem in compile with JDeveloper

    Compile with JDeveloper failded if the class didn't implement the abstract method of it's super abstract class. But it is ok wiht other IDE(VisualCafe, Eclipse, JBuilder...).
    It seems that JDeveloper is more strict than other IDEs.
    Anyone can tell me how to avoid this error? TIA.

    I've found out the reason.
    JDeveloper will try to compile all the source files the project used even they're not added into the project.
    I have ClassA extend abstract ClassB, and ClassB extend abstract ClassC and implement the abstract methods of ClassC, they can all be compiled. And then I got a wrong source file of classB which didn't has the methods. Maybe I've kept this wrong source file for a long time but didn't get any trouble until I began to use JDeveloper and got the error.
    Since I didn't add ClassB into the project and classB.class didn't changed. So I didn't noticed that a wrong source file caused the problem.
    Thank you! :-)

  • JOGL with SWING problem

    Hello i speak spanish my english is not good
    When i execute a java jogl program i've problem with swing.
    The jogl window catch the events from swing and execute
    accions out control.
    How can i lock the events from swing ?
    Thanks
    [email protected]

    jogl commands: translate, rotate ...
    When a box across the jogl window this commands
    are executed. This box is created with JOptionPane.
    i didnt find a solution yet.

  • Codepage problem when compiling with fastjavac

    Hi,
    I'm getting the following warnings when compiling with fastjavac:
    fastjavac: warning: Can't find codepage for "Cp1250" encoding.
    fastjavac: warning: Use default ANSI codepage.
    2 warnings
    How could I suppress these warnings?
    Thanks in advance

    I think you are posting it on the wrong Forum. This is for Forte 4GL not Forte for Java.

  • Problems compiling when calling other classes

    hello,
    following the Sun tutorial "How to build a application" i wrote this code...
    package divelog;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DiveLog extends JFrame{
         // make space in memory for a tabbed pane - not a object until constructor is called to initate
         private JTabbedPane tabbedPane;
         public DiveLog(){ //opens constructor - constructor iniaties objects
              super("Jason's DiveLog"); // super calls jframe - this is cause DiveLog extends JFrame
              addWindowListener(new WindowAdapter() // closes program form clicking "x" on the Jframe
              { //opens addWindowListener method
                   public void windowClosing(WindowEvent e){
                        System.exit(0);
         tabbedPane = new JTabbedPane(SwingConstants.LEFT);
         //tabbedPane.setBackground(Color.blue);
         //tabbedPane.setForeground(Color.white);
         // method to add tabs
         populateTabbedPane();
         //method builds menu
         buildMenu();
         // put on JFrame and set sizes
         getContentPane().add(tabbedPane);
         pack();
         setSize(765,690);
         setBackground(Color.white);
         setVisible(true);
         } //ends constructor started on line 13  - DiveLog()     
         // Methods -- for the constructor
         private void populateTabbedPane(){
              tabbedPane.addTab("Welcome",
                                                                null,
                                                                new Welcome(),
                                                                "Welcome to Jason's Dive Log");
              tabbedPane.addTab("Diver Data",
                                                                 null,
                                                                 new Diver(),
                                                                 "Click here to enter diver data");
              tabbedPane.addTab("Log Dives",
                                                                null,
                                                                new Dives(),
                                                                "Click here to enter dives");
              tabbedPane.addTab("Stats",
                                                                null,
                                                                new Statistics(),
                                                                "Click here to calculate stats");
         } // ends tabbed pane method
         private void buildMenu(){
              JMenuBar mb = new JMenuBar();
              JMenu menu = new JMenu("FIle");
              JMenuItem item = new JMenuItem("Exit");
              menu.add(item);
              mb.add(menu);
              setJMenuBar(mb);
              item.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e){
                        System.exit(0);
         }// ends buildMenu method
    } //ends class
              then... i made the welcome, dives,diver.... classes ...they look like this...
    package divelog;
    import javax.swing.*;
    import java.awt.*;
    public class Welcome extends JPanel{
    }all the .java files are in /home/mohadib/java_restore/DiveLog/
    so per the tutorial i try to compile with this.....
    javac -classpath /home/mohadib/java_restore/ DiveLog.java
    but i get this error....
    mohadib@mohadib ~/java_restore/DiveLog--->javac -classpath /home/mohadib/java_restore/ DiveLog.java
    DiveLog.java:48: cannot resolve symbol
    symbol : class Welcome
    location: class divelog.DiveLog
    new Welcome(),
    ^
    DiveLog.java:53: cannot resolve symbol
    symbol : class Diver
    location: class divelog.DiveLog
    new Diver(),
    ^
    DiveLog.java:58: cannot resolve symbol
    symbol : class Dives
    location: class divelog.DiveLog
    new Dives(),
    ^
    DiveLog.java:63: cannot resolve symbol
    symbol : class Statistics
    location: class divelog.DiveLog
    new Statistics(),
    ^
    4 errors
    could some one please tell me what im doing wrong :)
    Thanks,
    jd
              

    found the problem...
    i used this at the top of all the .java files....
    package divelog;
    then my dir tree looked like this....
    /home/mohadib/java_restore/DIveLog
    so i changed to
    /home/mohadib/java_restore/divelog
    and compiled with this....
    javac -classpath /home/mohadib/java_restore DiveLog.java
    then ran it with this.....
    java -classpath /home/mohadib/java_restore divelog.DiveLog
    thanks,
    jd

  • Problems working with events in JInternalFrames

    Hi everybody:
    I'm having a problem with Swing, I have a JFrame with two JInternalFrame's,
    I add the MouseListener's to work with the events MousePressed and MouseReleased and it simply doesn't work at all.
    Next you can see a fragment of my program, please tell me what I'm doing wrong.
    Thanks in advance.
    public class PicoPintador extends JFrame {
    private JDesktopPane desktop;
    private ventanaMonitor Monitor = new ventanaMonitor();
    private XYLayout xYLayout1 = new XYLayout();
    public PicoPintador() { /* THE CONSTRUCTOR */
    super("PicoPintador");
    try {
    jbInit();
    } catch (Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {  /* THE MAIN METHOD */
    PicoPintador picoPintador = new PicoPintador();
    picoPintador.setVisible(true);
    private void jbInit() throws Exception {
    desktop = new JDesktopPane();
    setContentPane(desktop);
    setContentPane(desktop);
    this.getContentPane().setLayout(xYLayout1);
    this.getContentPane().add(Monitor,
    new XYConstraints(30, 20, 230, 245));
    JInternalFrame PrimerDibujo = new JInternalFrame("Archivo 1");
    PrimerDibujo.getContentPane().setLayout(xYLayout1);
    PrimerDibujo.setResizable(true);
    PrimerDibujo.setClosable(true);
    PrimerDibujo.setMaximizable(true);
    PrimerDibujo.setIconifiable(true);
    PrimerDibujo.setSize(300,300);
    PrimerDibujo.setVisible(true);
    this.getContentPane().add(PrimerDibujo,
    new XYConstraints(30, 20, 230, 245));
    PrimerDibujo.setLocation(50,50);
         /* ADDING MOUSE THE FIRST LISTENER */
    Ventana.add(PrimerDibujo);
    PrimerDibujo.addMouseListener(
    new MouseAdapter(){
    public void mousePressed(MouseEvent evt){
    Monitor.setTEvento("Mouse Pressed");
         /* ADDING MOUSE THE SECOND LISTENER */
    PrimerDibujo.addMouseListener(
    new MouseAdapter(){
    public void mouseReleased(MouseEvent evt){
    Monitor.setTEvento("Mouse Released");
    /* THE CLASS ventanaMonitor */
    public class ventanaMonitor extends JInternalFrame {
    private JLabel tEvento;
    private JLabel evento;
    public ventanaMonitor() {
    try {
    jbInit();
    } catch (Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception {
    setClosable(false);
    Container ContentPane= getContentPane();
    ContentPane.setLayout(null);
    tEvento = new JLabel("Evento");
    evento = new JLabel();
    ContentPane.add(tEvento);
    ContentPane.add(evento);
    tEvento.setBounds(10, 80, 110, 15);
    evento.setBounds(140, 80, 110, 15);
    evento.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    setSize(300,300);
    setVisible(true);
    setLocation(250,50);
    }

    nothing wrong with the fragment you posted (except you don't need to add the listener twice)
    here's you code (stripped of the XYlayout and monitor stuff - you're only adding the listener to PrimerDibujo)
    compile/run/click the mouse - works OK
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class PicoPintador extends JFrame {
    private JDesktopPane desktop;
    public PicoPintador() {
    super("PicoPintador");
    try {
    jbInit();
    } catch (Exception e) {
    e.printStackTrace();
    public static void main(String[] args) { /* THE MAIN METHOD */
    PicoPintador picoPintador = new PicoPintador();
    picoPintador.setVisible(true);
    private void jbInit() throws Exception {
    setSize(800,600);
    desktop = new JDesktopPane();
    setContentPane(desktop);
    setContentPane(desktop);
    JInternalFrame PrimerDibujo = new JInternalFrame("Archivo 1");
    PrimerDibujo.setResizable(true);
    PrimerDibujo.setClosable(true);
    PrimerDibujo.setMaximizable(true);
    PrimerDibujo.setIconifiable(true);
    PrimerDibujo.setVisible(true);
    PrimerDibujo.setBounds(50, 50, 300, 300);
    this.getContentPane().add(PrimerDibujo);//,
    PrimerDibujo.addMouseListener(
    new MouseAdapter(){
    public void mousePressed(MouseEvent evt){
    System.out.println("Mouse Pressed");
    PrimerDibujo.addMouseListener(
    new MouseAdapter(){
    public void mouseReleased(MouseEvent evt){
    System.out.println("Mouse Released");
    }

  • Problems compiling program

    hello.
    this is james mcfadden. i'm having problems compiling the Demo.java program. the Demo.java program is shown below along with the MediaPanel.java and MediaTest.java programs. when i compile the Demo.java program i get the following errors. i really need help in getting rid of these errors.
    ----jGRASP exec: javac -g X:\CP4B Project\Demo.java
    Demo.java:297: cannot find symbol
    symbol : class Media
    location: class Demo
    MediaTest media=new Media();
    ^
    Demo.java:301: cannot find symbol
    symbol : class Media
    location: class Demo
    MediaTest media=new Media();
    ^
    Demo.java:305: cannot find symbol
    symbol : class Media
    location: class Demo
    MediaTest media=new Media();
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    //Written by:Seamus McFadden
    //Class:CP4B
    //Program Number:1
    //Program Name:Demo.java
    //Description:
    //Supervisor:Gerard McCloskey
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class Demo extends JFrame{
        public static void main(String[] args){
            int choice=-1;//a variable of type int that is set to -1
            choice=getChoice();//invokes the method getChoice()
            if(choice!=0){
               getSelected(choice);//invokes the method getSelected(choice)
            }//end if
        }//end main
        public static int getChoice(){
            String choice;//a variable of type string
            int ch;//a variable of type int
            choice=JOptionPane.showInputDialog(null,
                    "1. Product Menu\n" +
                    "2. Member Menu\n" +
                    "3. Rental Menu\n" +
                          "4. Media Menu\n" +
                    "5. Log Off\n\n" +
                    "Enter your choice");//asks the user for some input
            ch=Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object
            return ch;//a method that returns an integer value
        }//end getChoice
        public static void getSelected(int choice){
            if(choice == 1) {
                   product();
            }//end if
            if(choice==2){
               member();
            }//end if
            if(choice==3){
               rental();
            }//end if
                if(choice==4){
               media();
            }//end if
                if(choice==5){
                   LogOff logoff=new LogOff();
                }//end if
                else{
                   ErrorMessage error=new ErrorMessage();
        }//end getSelected
        public static void product(){
             int productChoice=-1;//a variable of type int that is set to -1
           productChoice=getProductChoice();//invokes the method getChoice()
           if(productChoice!=0){
              getProductSelected(productChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
        public static void member(){
           int memberChoice=-1;//a variable of type int that is set to -1
           memberChoice=getMemberChoice();//invokes the method getChoice()
           if(memberChoice!=0){
              getMemberSelected(memberChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
        public static void rental(){
           int rentalChoice=-1;//a variable of type int that is set to -1
           rentalChoice=getRentalChoice();//invokes the method getChoice()
           if(rentalChoice!=0){
              getRentalSelected(rentalChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice();
          public static void media(){
           int mediaChoice=-1;//a variable of type int that is set to -1
           mediaChoice=getMediaChoice();//invokes the method getChoice()
           if(mediaChoice!=0){
              getMediaSelected(mediaChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
          public static int getProductChoice(){
           String productChoice;//a variable of type string
           int pch;//a variable of type int
           productChoice=JOptionPane.showInputDialog(null,
                   "1. Add product details\n" +
                   "2. View product details\n" +
                   "3. Edit product details\n" +
                         "4. Delete product details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           pch=Integer.parseInt(productChoice);//a class that wraps a value of the primitive type int in an object
           return pch;//a method that returns an integer value
        }//end getProductChoice
          public static int getMemberChoice(){
           String memberChoice;//a variable of type string
           int mch;//a variable of type int
           memberChoice=JOptionPane.showInputDialog(null,
                   "1. Add member details\n" +
                   "2. View member details\n" +
                   "3. Edit member details\n" +
                             "4. Delete member details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           mch=Integer.parseInt(memberChoice);//a class that wraps a value of the primitive type int in an object
           return mch;//a method that returns an integer value
        }//end getMemberChoice
          public static int getRentalChoice(){
           String rentalChoice;//a variable of type string
           int rch;//a variable of type int
           rentalChoice=JOptionPane.showInputDialog(null,
                   "1. Add rental details\n" +
                   "2. View rental details\n" +
                   "3. Edit rental details\n" +
                             "4. Delete rental details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           rch=Integer.parseInt(rentalChoice);//a class that wraps a value of the primitive type int in an object
           return rch;//a method that returns an integer value
        }//end getRentalChoice
          public static int getMediaChoice(){
           String mediaChoice;//a variable of type string
           int mtch;//a variable of type int
           mediaChoice=JOptionPane.showInputDialog(null,
                   "1. Listen to songs\n" +
                             "2. View movie previews\n" +
                             "3. View game previews\n" +
                   "4. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           mtch=Integer.parseInt(mediaChoice);//a class that wraps a value of the primitive type int in an object
           return mtch;//a method that returns an integer value
        }//end getMediaChoice
          public static void getProductSelected(int productChoice){
           if(productChoice==1){
                  addProducts();
           }//end if
           if(productChoice==2){
              viewProducts();
           }//end if
           if(productChoice==3){
              editProducts();
           }//end if
               if(productChoice==4){
              deleteProducts();
           }//end if
               else{
                   ErrorMessage error=new ErrorMessage();
        }//end getProductSelected
          public static void getMemberSelected(int memberChoice){
           if(memberChoice==1){
                  addMembers();
           }//end if
           if(memberChoice==2){
              viewMembers();
           }//end if
           if(memberChoice==3){
              editMembers();
           }//end if
               if(memberChoice==4){
              deleteMembers();
           }//end if
               else{
                   ErrorMessage error=new ErrorMessage();
        }//end getMemberSelected
          public static void getRentalSelected(int rentalChoice){
           if(rentalChoice==1){
                  addRentals();
           }//end if
           if(rentalChoice==2){
              viewRentals();
           }//end if
           if(rentalChoice==3){
              editRentals();
           }//end if
               if(rentalChoice==4){
              deleteRentals();
           }//end if
               else{
                   ErrorMessage error=new ErrorMessage();
        }//end getRentalSelected
          public static void getMediaSelected(int mediaChoice){
           if(mediaChoice==1){
                  hearSongs();
           }//end if
           if(mediaChoice==2){
              viewMovies();
           }//end if
           if(mediaChoice==3){
              viewGames();
           }//end if
               else{
                   ErrorMessage error=new ErrorMessage();
        }//end getMediaSelected
          public static void addProducts(){
           ProductForm product=new ProductForm();
           product.getInput();
               product.setVisible(true);
          public static void viewProducts(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editProducts(){
           ProductForm product=new ProductForm();
               product.getInput();
               product.setVisible(true);
          public static void deleteProducts(){
           ProductForm product=new ProductForm();
               product.setVisible(true);
          public static void addMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void viewMembers(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void deleteMembers(){
           MemberForm member=new MemberForm();
               member.setVisible(true);
          public static void addRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void viewRentals(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void deleteRentals(){
           RentalForm rental=new RentalForm();
               rental.setVisible(true);
        public static void hearSongs(){
           MediaTest media=new Media(); 
        public static void viewMovies(){
           MediaTest media=new Media();   
        public static void viewGames(){
           MediaTest media=new Media();   
    }//end class Demo
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JPanel;
    public class MediaPanel extends JPanel{
       public MediaPanel(URL mediaURL){
          setLayout(new BorderLayout());//use a BorderLayout
          //Use lightweight components for Swing compatibility
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,true);
          try{
             //create a player to play the media specified in the URL
             Player mediaPlayer=Manager.createRealizedPlayer(mediaURL);
             //get the components for the video and the playback controls
             Component video=mediaPlayer.getVisualComponent();
             Component controls=mediaPlayer.getControlPanelComponent();
             if(video!=null)
                add(video,BorderLayout.CENTER);//add video component
             if(controls!=null)
                add(controls,BorderLayout.SOUTH);//add controls
             mediaPlayer.start();//start playing the media clip
          }//end try
          catch(NoPlayerException noPlayerException){
             System.err.println("No media player found");
          }//end catch
          catch(CannotRealizeException cannotRealizeException){
             System.err.println("Could not realize media player");
          }//end catch
          catch(IOException iOException){
             System.err.println("Error reading from the source");
          }//end catch
       }//end MediaPanel constructor
    }//end class MediaPanel
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    public class MediaTest{
       //launch the application
       public static void main(String args[]){
          //create a file chooser
          JFileChooser fileChooser=new JFileChooser();
          //show open file dialog
          int result=fileChooser.showOpenDialog(null);
          if(result==JFileChooser.APPROVE_OPTION){//user chose a file
             URL mediaURL=null;
             try{
                //get the file as URL
                mediaURL=fileChooser.getSelectedFile().toURL();
             }//end try
             catch(MalformedURLException malformedURLException){
                System.err.println("Could not create URL for the file");
             }//end catch
             if(mediaURL!=null) {//only display if there is a valid URL
                JFrame mediaTest=new JFrame("Media Tester");
                mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                MediaPanel mediaPanel=new MediaPanel(mediaURL);
                mediaTest.add(mediaPanel);
                mediaTest.setSize(300,300);
                mediaTest.setVisible(true);
             }//end inner if
          }//end outer if
       }//end main
    }//end class MediaTest

    hello.
    this is james mcfadden. thanks for the reply. i did what you told me to do, but i am still having trouble trying to use the 2 JMF programs (MediaPanel.java and MediaTest.java) with the Demo.java program. the Demo.java program compiles and runs ok, but when i press 1 (for listening to songs) in the media menu i get a JOptionPane (An Error Message) displayed on screen. how can i fix this problem?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Demo extends JFrame{
        public static void main(String[] args){
            int choice=-1;//a variable of type int that is set to -1
            choice=getChoice();//invokes the method getChoice()
            if(choice!=0){
               getSelected(choice);//invokes the method getSelected(choice)
            }//end if
        }//end main
        public static int getChoice(){
            String choice;//a variable of type string
            int ch;//a variable of type int
            choice=JOptionPane.showInputDialog(null,
                    "1. Product Menu\n" +
                    "2. Member Menu\n" +
                    "3. Rental Menu\n" +
                          "4. Media Menu\n" +
                    "5. Log Off\n\n" +
                    "Enter your choice");//asks the user for some input
            ch=Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object
            return ch;//a method that returns an integer value
        }//end getChoice
        public static void getSelected(int choice){
            if(choice == 1) {
                   product();
            }//end if
            if(choice==2){
               member();
            }//end if
            if(choice==3){
               rental();
            }//end if
                if(choice==4){
               media();
            }//end if
                if(choice==5){
                   LogOff logoff=new LogOff();
                }//end if
                else{
                   JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");
                   System.exit(0);
        }//end getSelected
        public static void product(){
             int productChoice=-1;//a variable of type int that is set to -1
           productChoice=getProductChoice();//invokes the method getChoice()
           if(productChoice!=0){
              getProductSelected(productChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
        public static void member(){
           int memberChoice=-1;//a variable of type int that is set to -1
           memberChoice=getMemberChoice();//invokes the method getChoice()
           if(memberChoice!=0){
              getMemberSelected(memberChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
        public static void rental(){
           int rentalChoice=-1;//a variable of type int that is set to -1
           rentalChoice=getRentalChoice();//invokes the method getChoice()
           if(rentalChoice!=0){
              getRentalSelected(rentalChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice();
          public static void media(){
           int mediaChoice=-1;//a variable of type int that is set to -1
           mediaChoice=getMediaChoice();//invokes the method getChoice()
           if(mediaChoice!=0){
              getMediaSelected(mediaChoice);//invokes the method getSelected(choice)
           }//end if
           getChoice(); 
          public static int getProductChoice(){
           String productChoice;//a variable of type string
           int pch;//a variable of type int
           productChoice=JOptionPane.showInputDialog(null,
                   "1. Add product details\n" +
                   "2. View product details\n" +
                   "3. Edit product details\n" +
                         "4. Delete product details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           pch=Integer.parseInt(productChoice);//a class that wraps a value of the primitive type int in an object
           return pch;//a method that returns an integer value
        }//end getProductChoice
          public static int getMemberChoice(){
           String memberChoice;//a variable of type string
           int mch;//a variable of type int
           memberChoice=JOptionPane.showInputDialog(null,
                   "1. Add member details\n" +
                   "2. View member details\n" +
                   "3. Edit member details\n" +
                             "4. Delete member details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           mch=Integer.parseInt(memberChoice);//a class that wraps a value of the primitive type int in an object
           return mch;//a method that returns an integer value
        }//end getMemberChoice
          public static int getRentalChoice(){
           String rentalChoice;//a variable of type string
           int rch;//a variable of type int
           rentalChoice=JOptionPane.showInputDialog(null,
                   "1. Add rental details\n" +
                   "2. View rental details\n" +
                   "3. Edit rental details\n" +
                             "4. Delete rental details\n" +
                   "5. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           rch=Integer.parseInt(rentalChoice);//a class that wraps a value of the primitive type int in an object
           return rch;//a method that returns an integer value
        }//end getRentalChoice
          public static int getMediaChoice(){
           String mediaChoice;//a variable of type string
           int mtch;//a variable of type int
           mediaChoice=JOptionPane.showInputDialog(null,
                   "1. Listen to songs\n" +
                             "2. View movie previews\n" +
                             "3. View game previews\n" +
                   "4. Return to main menu\n\n" +
                   "Enter your choice");//asks the user for some input
           mtch=Integer.parseInt(mediaChoice);//a class that wraps a value of the primitive type int in an object
           return mtch;//a method that returns an integer value
        }//end getMediaChoice
          public static void getProductSelected(int productChoice){
           if(productChoice==1){
                  addProducts();
           }//end if
           if(productChoice==2){
              viewProducts();
           }//end if
           if(productChoice==3){
              editProducts();
           }//end if
               if(productChoice==4){
              deleteProducts();
           }//end if
               else{
                   JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");
                   System.exit(0);
        }//end getProductSelected
          public static void getMemberSelected(int memberChoice){
           if(memberChoice==1){
                  addMembers();
           }//end if
           if(memberChoice==2){
              viewMembers();
           }//end if
           if(memberChoice==3){
              editMembers();
           }//end if
               if(memberChoice==4){
              deleteMembers();
           }//end if
               else{
                   JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");
                   System.exit(0);
        }//end getMemberSelected
          public static void getRentalSelected(int rentalChoice){
           if(rentalChoice==1){
                  addRentals();
           }//end if
           if(rentalChoice==2){
              viewRentals();
           }//end if
           if(rentalChoice==3){
              editRentals();
           }//end if
               if(rentalChoice==4){
              deleteRentals();
           }//end if
               else{
                   JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");
                   System.exit(0);
        }//end getRentalSelected
          public static void getMediaSelected(int mediaChoice){
           if(mediaChoice==1){
                  hearSongs();
           }//end if
           if(mediaChoice==2){
              viewMovies();
           }//end if
           if(mediaChoice==3){
              viewGames();
           }//end if
               else{
                   JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");
                   System.exit(0);
        }//end getMediaSelected
          public static void addProducts(){
           ProductForm product=new ProductForm();
           product.getInput();
               product.setVisible(true);
          public static void viewProducts(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editProducts(){
           ProductForm product=new ProductForm();
               product.getInput();
               product.setVisible(true);
          public static void deleteProducts(){
           ProductForm product=new ProductForm();
               product.setVisible(true);
          public static void addMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void viewMembers(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editMembers(){
           MemberForm member=new MemberForm();
               member.getInput();
               member.setVisible(true);
          public static void deleteMembers(){
           MemberForm member=new MemberForm();
               member.setVisible(true);
          public static void addRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void viewRentals(){
           DatabaseTest tt=new DatabaseTest();
               tt.setVisible(true);
          public static void editRentals(){
           RentalForm rental=new RentalForm();
               rental.getInput();
               rental.setVisible(true);
          public static void deleteRentals(){
           RentalForm rental=new RentalForm();
               rental.setVisible(true);
        public static void hearSongs(){
           MediaTest media=new MediaTest(); 
        public static void viewMovies(){
           MediaTest media=new MediaTest();   
        public static void viewGames(){
           MediaTest media=new MediaTest();   
    }//end class Demo
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JPanel;
    public class MediaPanel extends JPanel{
       public MediaPanel(URL mediaURL){
          setLayout(new BorderLayout());//use a BorderLayout
          //Use lightweight components for Swing compatibility
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,true);
          try{
             //create a player to play the media specified in the URL
             Player mediaPlayer=Manager.createRealizedPlayer(mediaURL);
             //get the components for the video and the playback controls
             Component video=mediaPlayer.getVisualComponent();
             Component controls=mediaPlayer.getControlPanelComponent();
             if(video!=null)
                add(video,BorderLayout.CENTER);//add video component
             if(controls!=null)
                add(controls,BorderLayout.SOUTH);//add controls
             mediaPlayer.start();//start playing the media clip
          }//end try
          catch(NoPlayerException noPlayerException){
             System.err.println("No media player found");
          }//end catch
          catch(CannotRealizeException cannotRealizeException){
             System.err.println("Could not realize media player");
          }//end catch
          catch(IOException iOException){
             System.err.println("Error reading from the source");
          }//end catch
       }//end MediaPanel constructor
    }//end class MediaPanel
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    public class MediaTest{
       //launch the application
       public static void main(String args[]){
          //create a file chooser
          JFileChooser fileChooser=new JFileChooser();
          //show open file dialog
          int result=fileChooser.showOpenDialog(null);
          if(result==JFileChooser.APPROVE_OPTION){//user chose a file
             URL mediaURL=null;
             try{
                //get the file as URL
                mediaURL=fileChooser.getSelectedFile().toURL();
             }//end try
             catch(MalformedURLException malformedURLException){
                System.err.println("Could not create URL for the file");
             }//end catch
             if(mediaURL!=null) {//only display if there is a valid URL
                JFrame mediaTest=new JFrame("Media Tester");
                mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                MediaPanel mediaPanel=new MediaPanel(mediaURL);
                mediaTest.add(mediaPanel);
                mediaTest.setSize(300,300);
                mediaTest.setVisible(true);
             }//end inner if
          }//end outer if
       }//end main
    }//end class MediaTest

  • Example code for java compiler with a simple GUI

    There is no question here (though discussion of the code is welcome).
    /* Update 1 */
    Now available as a stand alone or webstart app.! The STBC (see the web page*) has its own web page and has been improved to allow the user to browse to a tools.jar if one is not found on the runtime classpath, or in the JRE running the code.
    * See [http://pscode.org/stbc/].
    /* End: Update 1 */
    This simple example of using the JavaCompiler made available in Java 1.6 might be of use to check that your SSCCE is actually what it claims to be!
    If an SSCCE claims to display a runtime problem, it should compile cleanly when pasted into the text area above the Compile button. For a compilation problem, the code should show the same output errors seen in your own editor (at least until the last line of the output in the text area).
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.EventQueue;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JLabel;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import javax.swing.SwingWorker;
    import javax.swing.border.EmptyBorder;
    import java.util.ArrayList;
    import java.net.URI;
    import java.io.ByteArrayOutputStream;
    import java.io.OutputStreamWriter;
    import javax.tools.ToolProvider;
    import javax.tools.JavaCompiler;
    import javax.tools.SimpleJavaFileObject;
    /** A simple Java compiler with a GUI.  Java 1.6+.
    @author Andrew Thompson
    @version 2008-06-13
    public class GuiCompiler extends JPanel {
      /** Instance of the compiler used for all compilations. */
      JavaCompiler compiler;
      /** The name of the public class.  For 'HelloWorld.java',
      this would be 'HelloWorld'. */
      JTextField name;
      /** The source code to be compiled. */
      JTextArea sourceCode;
      /** Errors and messages from the compiler. */
      JTextArea output;
      JButton compile;
      static int pad = 5;
      GuiCompiler() {
        super( new BorderLayout(pad,pad) );
        setBorder( new EmptyBorder(7,4,7,4) );
      /** A worker to perform each compilation. Disables
      the GUI input elements during the work. */
      class SourceCompilation extends SwingWorker<String, Object> {
        @Override
        public String doInBackground() {
          return compileCode();
        @Override
        protected void done() {
          try {
            enableComponents(true);
          } catch (Exception ignore) {
      /** Construct the GUI. */
      public void initGui() {
        JPanel input = new JPanel( new BorderLayout(pad,pad) );
        Font outputFont = new Font("Monospaced",Font.PLAIN,12);
        sourceCode = new JTextArea("Paste code here..", 15, 60);
        sourceCode.setFont( outputFont );
        input.add( new JScrollPane( sourceCode ),
          BorderLayout.CENTER );
        sourceCode.select(0,sourceCode.getText().length());
        JPanel namePanel = new JPanel(new BorderLayout(pad,pad));
        name = new JTextField(15);
        name.setToolTipText("Name of the public class");
        namePanel.add( name, BorderLayout.CENTER );
        namePanel.add( new JLabel("Class name"), BorderLayout.WEST );
        input.add( namePanel, BorderLayout.NORTH );
        compile = new JButton( "Compile" );
        compile.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              (new SourceCompilation()).execute();
        input.add( compile, BorderLayout.SOUTH );
        this.add( input, BorderLayout.CENTER );
        output = new JTextArea("", 5, 40);
        output.setFont( outputFont );
        output.setEditable(false);
        this.add( new JScrollPane( output ), BorderLayout.SOUTH );
      /** Compile the code in the source input area. */
      public String compileCode() {
        output.setText( "Compiling.." );
        enableComponents(false);
        String compResult = null;
        if (compiler==null) {
          compiler = ToolProvider.getSystemJavaCompiler();
        if ( compiler!=null ) {
          String code = sourceCode.getText();
          String sourceName = name.getText().trim();
          if ( sourceName.toLowerCase().endsWith(".java") ) {
            sourceName = sourceName.substring(
              0,sourceName.length()-5 );
          JavaSourceFromString javaString = new JavaSourceFromString(
            sourceName,
            code);
          ArrayList<JavaSourceFromString> al =
            new ArrayList<JavaSourceFromString>();
          al.add( javaString );
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          OutputStreamWriter osw = new OutputStreamWriter( baos );
          JavaCompiler.CompilationTask task = compiler.getTask(
            osw,
            null,
            null,
            null,
            null,
            al);
          boolean success = task.call();
          output.setText( baos.toString().replaceAll("\t", "  ") );
          compResult = "Compiled without errors: " + success;
          output.append( compResult );
          output.setCaretPosition(0);
        } else {
          output.setText( "No compilation possible - sorry!" );
          JOptionPane.showMessageDialog(this,
            "No compiler is available to this runtime!",
            "Compiler not found",
            JOptionPane.ERROR_MESSAGE
          System.exit(-1);
        return compResult;
      /** Set the main GUI input components enabled
      according to the enable flag. */
      public void enableComponents(boolean enable) {
        compile.setEnabled(enable);
        name.setEnabled(enable);
        sourceCode.setEnabled(enable);
      public static void main(String[] args) throws Exception {
        Runnable r = new Runnable() {
          public void run() {
            JFrame f = new JFrame("SSCCE text based compiler");
            f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            GuiCompiler compilerPane = new GuiCompiler();
            compilerPane.initGui();
            f.getContentPane().add(compilerPane);
            f.pack();
            f.setMinimumSize( f.getSize() );
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        EventQueue.invokeLater(r);
    * A file object used to represent source coming from a string.
    * This example is from the JavaDocs for JavaCompiler.
    class JavaSourceFromString extends SimpleJavaFileObject {
      * The source code of this "file".
      final String code;
      * Constructs a new JavaSourceFromString.
      * @param name the name of the compilation unit represented
        by this file object
      * @param code the source code for the compilation unit
        represented by this file object
      JavaSourceFromString(String name, String code) {
        super(URI.create(
          "string:///" +
          name.replace('.','/') +
          Kind.SOURCE.extension),
          Kind.SOURCE);
        this.code = code;
      @Override
      public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        return code;
    }Edit 1:
    Added..
            f.setMinimumSize( f.getSize() );Edited by: AndrewThompson64 on Jun 13, 2008 12:24 PM
    Edited by: AndrewThompson64 on Jun 23, 2008 5:54 AM

    kevjava wrote: Some things that I think would be useful:
    Suggestions reordered to suit my reply..
    kevjava wrote: 2. Line numbering, and/or a line counter so you can see how much scrolling you're going to be imposing on the forum readers.
    Good idea, and since the line count is only a handful of lines of code to implement, I took that option. See the [line count|http://pscode.org/stbc/help.html#linecount] section of the (new) [STBC Help|http://pscode.org/stbc/help.html] page for more details. (Insert plaintiff whining about the arbitrary limits set - here).
    I considered adding line length checking, but the [Text Width Checker|http://pscode.org/twc/] ('sold separately') already has that covered, and I would prefer to keep this tool more specific to compilation, which leads me to..
    kevjava wrote: 1. A button to run the code, to see that it demonstrates the problem that you wish for the forum to solve...
    Interesting idea, but I think that is better suited to a more full blown (but still relatively simple) GUId compiler. I am not fully decided that running a class is unsuited to STBC, but I am more likely to implement a clickable list of compilation errors, than a 'run' button.
    On the other hand I am thinking the clickable error list is also better suited to an altogether more abled compiler, so don't hold your breath to see either in the STBC.
    You might note I have not bothered to update the screenshots to show the line count label. That is because I am still considering error lists and running code, and open to further suggestion (not because I am just slack!). If the screenshots update to include the line count but nothing else, take that as a sign. ;-)
    Thanks for your ideas. The line count alone is worth a few Dukes.

  • Do I need to make an applet with swing point to the JRE 1.4 plug-in?

    Do I need to make an applet with swing point to the JRE 1.4 plug-in? I mean, in 1.3.1 plug-in, if you did not run your code through the HTML converter, the applet would still use the browsers JRE (JVM). However, with 1.4.0, it seems that you don't need to. Is this correct?

    When you ran an applet that has been compiled under 1.4 and needs classes or methods from 1.4 with an old HTML file (presumedly with the <object> tag that still refers to JRE 1.3+), the browser is going to look at the <object> tag and see that at least JRE1.3.1 is needed to correctly run the applet and since 1.4, which is higher than 1.3+, is on the system, it ignorantly proceeds to load and run the applet. The problem that you're going to run into is when you deploy the applet on the web and your viewer only have JRE1.3+, your applet which really needs 1.4, will crap out....
    ;o)
    V.V.

Maybe you are looking for