Question about AWT vs. Swing

Say I'm building an applet. Which I am. Why should I choose AWT components over Swing? Or vise-versa? Swing seems "cooler" but I read somewhere that they're non-standard or harder to install/setup. Something like that.
Any advice before I begin hard work on my UI?

No version of ANY browser supports Swing without using the JRE. In most cases the page has to be converted to call the Java Plugin (which will be installed if the user has the JRE) before the JRE will be used to execute an applet. All the majority of users have is the VM that comes with their browser, which is stuck at something like JDK 1.1.6, which does not include Swing.
I would develop simple applets using only the AWT so that users can use the browser's VM. However if you have something more complex to do, I would require the user to have the Java Plugin, and then you can use Swing unto your Heart's Content.
Just some general thoughts about this issue:
I would like to move away from applets, and onto signed applications, which are downloaded and run from the user's machine. They can be kept up to date with the new Java WebStart (I believe), and will benefit from a newer VM, and more sophisticated language features. In addition it would lead to more users downloading the JRE, and the general spread of Java onto the client. I don't believe applets have a future beyond their current state, and let's face it, that state is quite lame.
Does anybody else have any thoughts on this issue?

Similar Messages

  • Question about JRE and Swing applications

    Hi i trying to make a Swing application whit some clients but one of them tell me that he have a lot of troubles whit java, because someone make an applet for his website and when he upgrade the JRE the applet dont work anymore.
    In my case i dont want any applets, i want swing, but a im not sure if
    swing uses the JRE and if the application im going to make, may have troubles when they upgrade de JRE.
    Tanks for de answers and sorry for my english

    In general, Java maintains upward compatibility (older code runs in newer Java releases.)
    Certain exceptions are made, and each major Java release identifies these. The current document can be read here:
    http://java.sun.com/j2se/1.5.0/compatibility.html

  • Simple question about awt

    Hi,
    i've got a program using awt, there's a button and i'd like that button to be default, i mean, if i strike enter i want that button to be pressed. How can i do that?

    button.requestFocus()

  • Quick question about subclasses in swing

    When you create a subclass of JFrame or JPanel, should you put super() in the constructor? It doesn't seem to make a difference either way.

    I never do it ...
    When you create new child classes, the parent classes constructors are called automatically.
    public class Inheritance {
        public static void main(String[] args) {
            new Child();
    class Parent{
        public Parent(){
            System.out.println("This is Parent");
    class Child extends Parent{
        public Child(){
            System.out.println("This is Child");
    Output
    This is Parent
    This is Child
    */

  • Question about  Buttons in swing

    How i can have circular button in GUI program.

    This code will get u through :
    JButton button = new JButton(new ImageIcon("roundImage.gif"));
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
    button.addActionListener(......);
    [email protected]

  • Difference between awt ang Swing Interview Question n other Question

    hi every one i use to think that i know java atlest so much that i can crack a lolcal comp interview but ........................
    i ansered few Question but was speachlees when was asked few of this i do not remember all of them
    1] difference between awt and swing.
    2]System.out.println();
    System is a class out is a variable so who come a variable calling a method.
    3]are constractor inherateed in java.

    1] difference between awt and swing.AWT is based on an abstraction of platform-specific, heavy-weight components. Swing is written entirely in java.
    >
    2]System.out.println();
    System is a class out is a variable so who come a
    variable calling a method.Do you mean how come?
    In that case, the answer is simple: Because out is a variable, it can be redirected/compared against, etc much easier
    3]are constractor inherateed in java.Kind of a trick question, as the answer is yes and no. Constructors are not inherited, but every constructor in the subclass must call one and exactly one constructor of the superclass

  • Swing isn't thread safe, what about AWT?

    Since Swing isn't really thread safe what does that mean for AWT? Is AWT thread safe? Also if it is doesn't that mean one should use AWT over Swing since AWT is thread safe?

    Trizi wrote:
    jverd wrote:
    Trizi wrote:
    [http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0|http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0]
    There ya go duffy the hom^oYou say that is if being gay were a bad thing. So, besides being an obnoxious fuckhead, you're also a homophobic troglodyte? Man your fiancee must be a real winner to have picked you. My guess is that she's either a sheep, a blow-up doll, or someone you've got bound and gagged in your basement.Now from what everyone is saying that I don't have anything original...
    You don't either, too much "Silence of the Lambs" maybe?Dude, try speaking English.
    By the way, I am sure if I was a troglodyte I would be in a museum, also I have homosexual friends, sorry not homophobic, I just found a good ting to his name and figured I'd exploit it.. Just like I'm exploiting your pathetic intelligence.You really need help if you think the above makes any sense or any point.

  • Questions about ActiveX Bridge and SWT

    Hi !
    I found few weeks ago the www.reallyusefulcomputing.com site answering my question about Java & Macro of MSWord. Now I've found two steps that I am not able to overcome.
    First, when I build a simple application and I have internal libraries to use, am I compelled to place the jars in the lib/ext directory of the Java Runtime Directory? I have many difficulties in placing a convenient class-path in the manifest file. Why does the application ignore the manifest string?
    The second problem (and the biggest one) is that I am trying to build an SWT java-bean-application but I have problems during runtime. Is it possible to use this technology for my software or am I compelled to use AWT and SWING?
    I really hope you can help me.
    Thank you in advance.

    hi,
    I have to catch events from excel sheet in my java code..events like some change in value or a click of some user defined button etc.I have written th follwoing code but it does not gives me any event.It simply opens the specified file in the excel in a seperate window.but when i click on the sheet or change some value no event is captured by my code....can ne one pls tell me how to go about it....
    public class EventTry2 {
         private Shell shell;
         private static OleAutomation automation;
         static OleControlSite controlSite;
         protected static final int Activate = 0x00010130;
         protected static final int BeforeDoubleClick = 0x00010601;
         protected static final int BeforRightClick = 0x000105fe;
         protected static final int Calculate = 0x00010117;
         protected static final int Change = 0x00010609;
         protected static final int Deactivate = 0x000105fa;
         protected static final int FollowHyperlink = 0x000105be;
         protected static final int SelectionChange = 0x00010607;
         public void makeVisible()
              Variant[] arguments = new Variant[1];
              arguments[0]=new Variant("true");
              //Visible---true
              automation.setProperty(558,arguments);
              //EnableEvent--true
              boolean b =automation.setProperty(1212,arguments);
            System.out.println(b);
             public Shell open(Display display){
             this.shell=new Shell(display);
              this.shell.setLayout(new FillLayout());
              Menu bar = new Menu(this.shell,SWT.BAR);
              this.shell.setMenuBar(bar);
              OleFrame frame = new OleFrame(shell,SWT.NONE);
            File file= new File("C:\\Book1.xls");
              try{
              controlSite =  new OleControlSite(frame, SWT.NONE, "Excel.Application");
              this.shell.layout();
              boolean a2=true;
              a2=(controlSite.doVerb(OLE.OLEIVERB_SHOW|OLE.OLEIVERB_OPEN|OLE.OLEIVERB_UIACTIVATE|OLE.OLEIVERB_HIDE|OLE.OLEIVERB_PROPERTIES|OLE.OLEIVERB_INPLACEACTIVATE)== OLE.S_OK);
              System.out.println("Activated::\t"+a2);
            }catch(SWTException ex)
                 System.out.println(ex.getMessage());
                 return null;
              automation = new OleAutomation(controlSite);
              //make the application visible
              makeVisible();
              System.out.println("Going to create Event listener");
              OleListener eventListener=new OleListener(){
                   public void handleEvent(OleEvent event){
                        System.out.println("EVENT TYPE==\t"+event.type);
                   switch(event.type){
                   case Activate:{
                        System.out.println("Activate Event");
                   case BeforeDoubleClick:{
                        System.out.println("BeforeDoubleClick Event");
                   case BeforRightClick:{
                        System.out.println("BeforeRightClick Event");
                   case Calculate:{
                        System.out.println("Calculate Event");
                   case Change:{
                        System.out.println("Change Event");
                   case Deactivate:{
                        System.out.println("DeActivate Event");
                   case FollowHyperlink:{
                        System.out.println("Activate Event");
                   case SelectionChange:{
                        System.out.println("Activate Event");
                        Variant[] arguments = event.arguments;
                        for(int i=0;i<arguments.length;i++)
                             System.out.println("@@");
                             arguments.dispose();
              System.out.println("outside");
              OleAutomation sheetAutomation=this.openFile("C:\\Book1.xls");
              controlSite.addEventListener(sheetAutomation,Activate,eventListener);
              controlSite.addEventListener(sheetAutomation,BeforeDoubleClick,eventListener);
              controlSite.addEventListener(sheetAutomation,BeforRightClick,eventListener);
              controlSite.addEventListener(sheetAutomation,Calculate,eventListener);
              controlSite.addEventListener(sheetAutomation,Change,eventListener);
              controlSite.addEventListener(sheetAutomation,Deactivate,eventListener);
              controlSite.addEventListener(sheetAutomation,FollowHyperlink,eventListener);
              controlSite.addEventListener(sheetAutomation,SelectionChange,eventListener);
              shell.open();
              return shell;
         public OleAutomation openFile(String fileName)
              Variant workbooks = automation.getProperty(0x0000023c);//get User Defined Workbooks
              Variant[] arguments = new Variant[1];
              arguments[0]= new Variant(fileName);
              System.out.println("workbooks::\t"+workbooks);
              IDispatch p1=workbooks.getDispatch();
              int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[]{"Open"});
              int dispIdMember = rgdispid[0];
              Variant workbook = workbooks.getAutomation().invoke( dispIdMember, arguments );
              System.out.println("Opened the Work Book");
              try {
                   Thread.sleep(500);
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              int id = workbook.getAutomation().getIDsOfNames(new String[]{"ActiveSheet"})[0];
              System.out.println(id);
              Variant sheet = workbook.getAutomation().getProperty( id );
              OleAutomation sheetAutomation=sheet.getAutomation();
              return(sheetAutomation);
         * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Display display=new Display();
              Shell shell=(new EventTry2()).open(display);
              while(!shell.isDisposed()){
                   if(!display.readAndDispatch()){
                        display.sleep();
              controlSite.dispose();
              display.dispose();
              System.out.println("-----------------THE END-----------------------------");

  • Lighter Java GUI than awt and swing?

    I had recently came across a company website (http://www.bambookit.com) where they developed a java gui library without using awt and swing (seems to what they claim). And on top of that it uses xml to generate the gui components (they call widgets) and the whole library size is only 95kb and supports java 1.1.x and above. Their demos on the applets loads super fast, never know/experience that java applets can actually be this quick. But this confuses me, how is it possible to develop a gui alternative to awt with the basic java classes and no dependency on awt? But since the applets are awt based, it means that they must have some dependencies.
    This is an extract from their website (that it seemed they did not use awt)
    "Java has a fundamental flaw in its paint thread that made it very difficult to build extremely large applications without getting severe performance and resource penalties (This affects both AWT and Swing based applications). It�s main repaint queue\thread when assigning paint regions to various controls uses the Graphics objects to �clip� them. On a Sun Solaris machine this does not cause any problems, however on a windows machine each Graphics object consumes a system resource/handle, (a limit of around 16,000 exists on Win 95 and Win 98 machines). Each Bitmap image, each font object, each icon consumes a single system resource or handle. If a full repaint is performed on an application containing 1000 controls, it would consume at LEAST 1000 system resource handles. If the application was updated many times a second, lets say 10 times a second, then that equates to 10,000 handles a second. This is not taking into account labels within controls, the various fonts styles and sizes created, the various images that get loaded. This could easily exceed 20,000 system resource requests a second. Bambookit on the other hand utilizes the clip routines and passes along a SINGLE Graphics objects to all its various controls. This alone is a HUGE savings in system resources and performance."
    Two questions came to my mind:
    1) Is it possible to build applet gui without using awt and swing in java? If so the only way to do is to use JNI calls?
    2) Am I wrong in interpreting www.bambookit.com's message that they are not using awt?
    Any comments about this?
    Regards,
    Stanly

    They use AWT as basis for their drawing-layer, as any other lightweight toolkits too.
    If you just want a very fast & light alternative to swing/awt have a look at www.lwvcl.com !
    I use it for a large applet-applikation that has to be java-1.1 compatible. It was a horor when using AWT which was implemented different over all JVMs available and very slow (although native widgets were used).
    With lwvcl (which has only 150kB!) I can use state of the art applets that work very fast on modern jvms like 1.4, give me the ability to compile my applikation to native code using GCJ (using the swt-prt of the library) or distribute it to old-school 1.1 browser where it also runs quite fine...
    Its free for GPL and very cheap for commercial use.
    lg Clemens

  • Basic questions about programing for J9 VM

    I need to create a java application to run on a Pocket PC 2003 OS and I'm limited to using IBM's Websphere J9 Virtual Machine. I'm new to using java in this capacity and therefore have lots of questions which I'm guessing are pretty basic. Despite my best efforts, I've found very little to help me online. Below are a couple questions I have that I'm hoping someone can help me with. Even better, if you know of any resources that could help me with these and other questions, I'd love to have them. Thanks in advance.
    1. I'm using standard AWT for the GUI but I'm having problems getting frames, dialogs, etc., to come up in anything less then full screen. setSize() and resize() have no effect, even if I extend the frame and override the setMinimumSize, setPreferredSize, setMaximumSize methods. What do I need to do to get a child window to appear in something less than full screen?
    2. I'd like to be able to add menu's to the buttom toolbar (with the keyboard) but have no idea how I would add something to it. Can someone point me in the right direction?
    3. When my application gets an iconified event I go ahead and call a System.exit() to exit the application. This doesn't kill the java VM though, which continues to run in the background (taking up plenty of memory). If I run my application using the J9w.exe so that it runs without the console, then not only does the VM continue to run, but I have no way to stop it (the running program list can't see it). Since each time I run my application it starts a new VM, it only takes a couple of times before I'm out of memory and have to do a soft reset of the PDA to make things right. Can I kill the VM when I kill my application?
    4. I learn best by looking at example code, but have been unable to find any code people are running on J9. I have the GolfScoreTracker installed and running on my PDA, but the jar file contains only the classes. Since it's supposed to be a demo, I had hoped that the source code would be included, is that hoping too much or is the source code available somewhere? In addition, if you know of any applications out there with available source code that are known to run well on a PocketPC J9 environment I'd appreciate the link.

    Hi there, I saw your questions, im currently developing a java pocket pc application as well and here's what i go so far:
    AWT seem to be hard to use on pocket pc, instead i recommend that you use SWT, which is a technology developed by eclipse. It's already installed on the eclipse plugins, you just need to download the jar and dll files for the pocket pc. They are available at: http://www.eclipse.org/downloads/index.php
    I assume that you already have the J9 working on your device. So you only need to copy the SWT.jar file and the swt-win32-3064.dll to the folder containing the .class files on your device.
    Now, on your java IDE(im using eclipse) Add the SWT.jar library to your project which should be on C:/eclipse/plugins/org.eclipse.swt.win32_3.0.2/ws/win32/swt.jar or something like taht depending on your eclipse root.
    Now you are ready to code some SWT, here is a sample program from Carolyn MacLeod, i modified a few things so it could run on the pocket pc but it's almost the same. Once you coded in eclipse run it, then copy the class file from your desktop to your device(There should be like 4 or 5 classes like sample.class, sample$1.class etc. copy all of them) where you put the jar and dll files(If program does not run you may try to rename the dll file for swt-win32-3050.dll instead of 3064.dll). Now after you have everything set up you need to create the lnk file in order to run the program. On your desktop create a new textfile and write the following on it:
    255#"\Archivos de Programa\J9\PPRO10\bin\j9w.exe" "-jcl:PPRO10" "-cp" "\My
    Documents\Java\swt.jar" ;\My Documents\Java" sample
    Paths depend on your install, and the place where you put your classes and jar file. path for j9w is usually "\Program Files\J9\PPRO10\bin\j9w.exe", and the last word should be the classname.
    Currently this form only displays an image on a canvas, click on the browse button and choose a pic and it will display on the canvas. Im trying to connect the form to an oracle database but no success yet on the device.
    Hope it helps, if you have any questions about the code or something, and I know the answer, please feel free to ask.
    See ya
    import org.eclipse.swt.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.events.*;
    import org.eclipse.swt.graphics.*;
    public class sample {
    static Shell shell;
    static Display display;
    static Text dogName;
    static Text textdb;
    static Combo dogBreed;
    static Canvas dogPhoto;
    static Image dogImage;
    static List categories;
    static Text ownerName;
    static Text ownerPhone;
    static String[] FILTER_EXTS = {"*.jpg"};
    public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display, SWT.RESIZE | SWT.CLOSE);
    Menu menu = new Menu(shell, SWT.BAR);
    shell.setText("Dog ShowS Entry");
    shell.setMenuBar(menu);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    shell.setLayout(gridLayout);
    new Label(shell, SWT.NONE).setText("Dog's NameS:");
    dogName = new Text(shell, SWT.SINGLE | SWT.BORDER);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    gridData.widthHint = 60;
    dogName.setLayoutData(gridData);
    new Label(shell, SWT.NONE).setText("Breed:");
    dogBreed = new Combo(shell, SWT.NONE);
    dogBreed.setItems(new String [] {"Collie", "Pitbull", "Poodle", "Scottie"});
    dogBreed.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    Label label = new Label(shell, SWT.NONE);
    label.setText("Categories");
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    new Label(shell, SWT.NONE).setText("Photo:");
    dogPhoto = new Canvas(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 60;
    gridData.verticalSpan = 3;
    dogPhoto.setLayoutData(gridData);
    dogPhoto.addPaintListener(new PaintListener() {
    public void paintControl(final PaintEvent event) {
    if (dogImage != null) {
    event.gc.drawImage(dogImage, 0, 0);
    categories = new List(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    categories.setItems(new String [] {
    "Best of Breed", "Prettiest Female", "Handsomest Male",
    "Best Dressed", "Fluffiest Ears", "Most Colors",
    "Best Performer", "Loudest Bark", "Best Behaved",
    "Prettiest Eyes", "Most Hair", "Longest Tail",
    "Cutest Trick"});
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.widthHint = 60;
    gridData.verticalSpan = 4;
    int listHeight = categories.getItemHeight() * 12;
    Rectangle trim = categories.computeTrim(0, 0, 0, listHeight);
    gridData.heightHint = trim.height;
    categories.setLayoutData(gridData);
    Button browse = new Button(shell, SWT.PUSH);
    browse.setText("BrowsePic");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.widthHint = 60;
    browse.setLayoutData(gridData);
    browse.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
              FileDialog dialog = new FileDialog(shell, SWT.OPEN);
              dialog.setFilterExtensions(new String[] {"*.*"});
              String fileName = dialog.open();
    if (fileName != null) {
    dogImage = new Image(display, fileName);
    shell.redraw();
    Button delete = new Button(shell, SWT.PUSH);
    delete.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    gridData.widthHint = 60;
    delete.setLayoutData(gridData);
    delete.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
    Button enter = new Button(shell, SWT.PUSH);
    enter.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    enter.setLayoutData(gridData);
    enter.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
         shell.open();
         while (!shell.isDisposed()) {
              if (!display.readAndDispatch())
                   display.sleep();
         display.dispose();
    if (dogImage != null) {
    dogImage.dispose();
    }

  • Question to understand javax.swing.plaf.FontUIResource("Arial Unicode MS"..

    Hi Commuity!
    I have an Question about this function!
    javax.swing.plaf.FontUIResource("Arial Unicode MS", Font.PLAIN, 12);
    I have read the Java doc but this didn�t help!
    I wanted to know, what happend, if this Font is not an the Client.
    So i deleted the Font "Arial Unicode MS".
    But the applikation still use this Font. But it is not on my local PC?
    Were do Swing load the Font�s from?
    Are the Fonts included in Java?
    thx a lot
    Florian

    Has got nobody an idea, where swing load the fonts from?

  • Questions about Access Manager tutorials available in netbeans site

    Hi
    Thank you for reading my post
    I have some questions about two tutoral which i find in :
    http://www.netbeans.org/kb/55/amsecurity.html and
    http://www.netbeans.org/kb/55/amsecurity-liberty.html
    here is my problem :
    we have some web services, now we want to have authentication applied for consumer who try to access our web services.
    we need to have most possible flexibility because we may deploy the server for a customer with an already established Identity database ( Database Table with user details)
    Also we need to have Transport level security using SSL.
    I read and studied both of them and now i have some questions :
    -I think Securing Web Services Using the SAML or UserNameToken is what we need for authentication and autorization of web service consumers?
    is that right?
    -Does Sun Java System Access Manager provide flexibility to authenticate user/password with a database table content?
    -How we can apply roles in Sun Java System Access Manager when we authenticate users ?
    Thanks

    Imagine that we want to have an end to end security for our web services
    we thought that we could use message level encryption to protect the soap message and also we should protect our web services from un-authenticated acess,
    we will use userName token for this.
    Our customer has large database which contains many user/password and role of those users.
    some of web services should be available to higher role (manager) and not for all users.
    so we should check a user role before we allows him/her to access a web service.
    my question is whether Sun Access manager can help us with this? or there are other configuration or packages that we should apply to have this feature.
    to explain more :
    our client side is a swing application, users enter username/password to login into system. after they loged in, we send user/pass every time user want to request some data from some services. (is it good to send user/pass every time?)
    We want Sun Access Manager to handle users authentication .
    We also need to handle role related authorization, can Sun access manager handle this?
    Thanks

  • Catching events on Desktop , without using any AWT or Swing components.

    How can I catch events(for eg: mouse clicks) on the Desktop? I do not want to use any AWT or Swing components in my application.
    Also, i want to get events even some other java/non-java application windows are visible on desktop, as long as my application is running.

    Myrequirement is to capture all AWT events, regardless of on which component its being happened.
    I mean I have to capture events outside the current running application (on desktop and any other java/no-java appliation windows also).
    I couldn't find any other forum which discusses about event handling.
    This is part of my app. other end extensively uses awt.

  • Questions about JavaFX

    Hi all,
    I'm new to JavaFX. I have a couple of questions about this new technology.
    1. Can JavaFX provides a GUI layer like SWING in a standalone application where the GUI collects input and sends a request to the core application?
    2. Regarding Web applications, what can JavaFX do? I guess JavaFX allows us to create applets, and it does not provide what JSPs/Servlets or JSF do. Is it right?
    Thank you very much!

    The new technology is already 6 months old and the version 1.2 have just been released... :-)
    Which is good news: yes, JavaFX has now a rather complete GUI layer. Previously it depended on Swing to provide most GUI components, now it has native components.
    So it can indeed collect (and display) information and send requests to a server (via HttpRequest class).
    JavaFX is on the client side: you can create applets, drag them to the desktop, start programs with JNLP or even as standalone applications. But it is not suitable to build Web pages on the server side, so no JSP/JSF/Servlets. But it can communicate with them, of course.

  • Help Plz! AWT to Swing Conversion

    Hey everyone, I'm new to java and trying to convert this AWT program to Swing, I got no errors, the menu shows but they dont work !! Could somebody please help me? thanks alot!
    Current Under-Construction Code: (no errors)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class zipaint extends JFrame implements ActionListener,      ItemListener,
    MouseListener, MouseMotionListener, WindowListener {
    static final int WIDTH = 800;     // Sketch pad width
    static final int HEIGHT = 600;     // Sketch pad height
    int upperLeftX, upperLeftY;     // Rectangle upper left corner coords.
    int width, height;          // Rectangle size
    int x1, y1, x2, y2, x3, y3, x4, y4; // Point coords.
    boolean fillFlag = false; //default filling option is empty
    boolean eraseFlag = false; //default rubber is off
    String drawColor = new String("black"); //default drawing colour is black
    String drawShape = new String("brush"); //default drawing option is brush
    Image background; //declear image for open option
    private FileDialog selectFile = new FileDialog( this,
    "Select background (.gif .jpg)",
    FileDialog.LOAD );
    // Help
    String helpText = "Draw allows you to sketch different plane shapes over a " +
    "predefined area.\n" + "A shape may be eother filled or in outline, " +
    "and in one of eight different colours.\n\n" + "The position of the " +
    "mouse on the screen is recorded in the bottom left-hand corner of the " +
    "drawing area. The choice of colour and shape are disoplayed also in the " +
    "left-habnd corner of the drawing area.\n\n" + "The size of a shape is " +
    "determined by the mouse being dragged to the final position and " +
    "released. The first click of the mouse will generate a reference dot on " +
    "the screen. This dot will disapear after the mouse button is released.\n\n" +
    "Both the square and the circle only use the distance measured along the " +
    "horizontal axis when determining the size of a shape.\n\n" + "Upon " +
    "selecting erase, press the mouse button, and move the mouse over the " +
    "area to be erased. releasing the mouse button will deactivate erasure.\n\n" +
    "To erase this text area choose clearpad from the TOOLS menu.\n\n";
    // Components
    JTextField color = new JTextField();
    JTextField shape = new JTextField();
    JTextField position = new JTextField();
    CheckboxGroup fillOutline = new CheckboxGroup();
    JTextArea info = new JTextArea(helpText,0,0/*,JTextArea.JSCROLLBARS_VERTICAL_ONLY*/);
    JFrame about = new JFrame("About Zi Paint Shop");
    // Menues
    String[] fileNames = {"Open","Save","Save as","Exit"};
    String[] colorNames = {"black","blue","cyan","gray","green","magenta","red","white","yellow"};
    String[] shapeNames = {"brush","line","square","rectangle","circle","ellipse"};
    String[] toolNames = {"erase","clearpad"};
    String[] helpNames = {"Help","about"};
    public zipaint(String heading) {
    super(heading);
    getContentPane().setBackground(Color.white);
    getContentPane().setLayout(null);
    /* Initialise components */
    initialiseTextFields();
    initializeMenuComponents();
    initializeRadioButtons();
    addWindowListener(this);
    addMouseListener(this);
    addMouseMotionListener(this);
    /* Initialise Text Fields */
    private void initialiseTextFields() {
    // Add text field to show colour of figure
    color.setLocation(5,490);
    color.setSize(80,30);
    color.setBackground(Color.white);
    color.setText(drawColor);
    getContentPane().add(color);
    // Add text field to show shape of figure
    shape.setLocation(5,525);
    shape.setSize(80,30);
    shape.setBackground(Color.white);
    shape.setText(drawShape);
    getContentPane().add(shape);
    // Add text field to show position of mouse
    position.setLocation(5,560);
    position.setSize(80,30);
    position.setBackground(Color.white);
    getContentPane().add(position);
    // Set up text field for help
    info.setLocation(150,250);
    info.setSize(500,100);
    info.setBackground(Color.white);
    info.setEditable(false);
    private void initializeMenuComponents() {
    // Create menu bar
    JMenuBar bar = new JMenuBar();
    // Add colurs menu
    JMenu files = new JMenu("Files");
    for(int index=0;index < fileNames.length;index++)
    files.add(fileNames[index]);
    bar.add(files);
    files.addActionListener(this);
    // Add colurs menu
    JMenu colors = new JMenu("COLORS");
    for(int index=0;index < colorNames.length;index++)
    colors.add(colorNames[index]);
    bar.add(colors);
    colors.addActionListener(this);
    // Add shapes menu
    JMenu shapes = new JMenu("SHAPES");
    for(int index=0;index < shapeNames.length;index++)
    shapes.add(shapeNames[index]);
    bar.add(shapes);
    shapes.addActionListener(this);
    // Add tools menu
    JMenu tools = new JMenu("TOOLS");
    for(int index=0;index < toolNames.length;index++)
    tools.add(toolNames[index]);
    bar.add(tools);
    tools.addActionListener(this);
    // Add help menu
    JMenu help = new JMenu("HELP");
    for(int index=0;index < helpNames.length;index++)
    help.add(helpNames[index]);
    bar.add(help);
    help.addActionListener(this);
    // Set up menu bar
    setJMenuBar(bar);
    /* Initilalise Radio Buttons */
    private void initializeRadioButtons() {
    // Define checkbox
    Checkbox fill = new Checkbox("fill",fillOutline,false);
    Checkbox outline = new Checkbox("outline",fillOutline,true);
    // Fill buttom
    fill.setLocation(5,455);
    fill.setSize(80,30);
    getContentPane().add(fill);
    fill.addItemListener(this);
    // Outline button
    outline.setLocation(5,420);
    outline.setSize(80,30);
    getContentPane().add(outline);
    outline.addItemListener(this);
    /* Action performed. Detects which item has been selected from a menu */
    public void actionPerformed(ActionEvent e) {
    Graphics g = getGraphics();
    String source = e.getActionCommand();
    // Identify chosen colour if any
    for (int index=0;index < colorNames.length;index++) {
    if (source.equals(colorNames[index])) {
    drawColor = colorNames[index];
    color.setText(drawColor);
    return;
    // Identify chosen shape if any
    for (int index=0;index < shapeNames.length;index++) {
    if (source.equals(shapeNames[index])) {
    drawShape = shapeNames[index];
    shape.setText(drawShape);
    return;
    // Identify chosen tools if any
    if (source.equals("erase")) {
    eraseFlag= true;
    return;
    else {
    if (source.equals("clearpad")) {
    remove(info);
    g.clearRect(0,0,800,600);
    return;
    if (source.equals("Open")) {
    selectFile.setVisible( true );
    if( selectFile.getFile() != null )
    String fileLocation = selectFile.getDirectory() + selectFile.getFile();
    background = Toolkit.getDefaultToolkit().getImage(fileLocation);
    paint(getGraphics());
    if (source.equals("Exit")) {
    System.exit( 0 );
    // Identify chosen help
    if (source.equals("Help")) {
    getContentPane().add(info);
    return;
    if (source.equals("about")) {
    displayAboutWindow(about);
    return;
    public void paint(Graphics g)
    super.paint(g);
    if(background != null)
    Graphics gc = getGraphics();
    gc.drawImage( background, 0, 0, this.getWidth(), this.getHeight(), this);
    /* Dispaly About Window: Shows iformation aboutb Draw programme in
    separate window */
    private void displayAboutWindow(JFrame about) {
    about.setLocation(300,300);
    about.setSize(350,160);
    about.setBackground(Color.cyan);
    about.setFont(new Font("Serif",Font.ITALIC,14));
    about.setLayout(new FlowLayout(FlowLayout.LEFT));
    about.add(new Label("Author: Zi Feng Yao"));
    about.add(new Label("Title: Zi Paint Shop"));
    about.add(new Label("Version: 1.0"));
    about.setVisible(true);
    about.addWindowListener(this);
    // ----------------------- ITEM LISTENERS -------------------
    /* Item state changed: detect radio button presses. */
    public void itemStateChanged(ItemEvent event) {
    if (event.getItem() == "fill") fillFlag=true;
    else if (event.getItem() == "outline") fillFlag=false;
    // ---------------------- MOUSE LISTENERS -------------------
    /* Blank mouse listener methods */
    public void mouseClicked(MouseEvent event) {}
    public void mouseEntered(MouseEvent event) {}
    public void mouseExited(MouseEvent event) {}
    /* Mouse pressed: Get start coordinates */
    public void mousePressed(MouseEvent event) {
    // Cannot draw if erase flag switched on.
    if (eraseFlag) return;
    // Else set parameters to 0 and proceed
    upperLeftX=0;
    upperLeftY=0;
    width=0;
    height=0;
    x1=event.getX();
    y1=event.getY();
    x3=event.getX();
    y3=event.getY();
    Graphics g = getGraphics();
    displayMouseCoordinates(x1,y1);
    public void mouseReleased(MouseEvent event) {
    Graphics g = getGraphics();
    // Get and display mouse coordinates
    x2=event.getX();
    y2=event.getY();
    displayMouseCoordinates(x2,y2);
    // If erase flag set to true reset to false
    if (eraseFlag) {
    eraseFlag = false;
    return;
    // Else draw shape
    selectColor(g);
    if (drawShape.equals("line")) g.drawLine(x1,y1,x2,y2);
    else if (drawShape.equals("brush"));
    else drawClosedShape(drawShape,g);
    /* Display Mouse Coordinates */
    private void displayMouseCoordinates(int x, int y) {
    position.setText("[" + String.valueOf(x) + "," + String.valueOf(y) + "]");
    /* Select colour */
    private void selectColor(Graphics g) {
    for (int index=0;index < colorNames.length;index++) {
    if (drawColor.equals(colorNames[index])) {
    switch(index) {
    case 0: g.setColor(Color.black);break;
    case 1: g.setColor(Color.blue);break;
    case 2: g.setColor(Color.cyan);break;
    case 3: g.setColor(Color.gray);break;
    case 4: g.setColor(Color.green);break;
    case 5: g.setColor(Color.magenta);break;
    case 6: g.setColor(Color.red);break;
    case 7: g.setColor(Color.white);break;
    default: g.setColor(Color.yellow);
    /* Draw closed shape */
    private void drawClosedShape(String shape,Graphics g) {
    // Calculate correct parameters for shape
    upperLeftX = Math.min(x1,x2);
    upperLeftY = Math.min(y1,y2);
    width = Math.abs(x1-x2);
    height = Math.abs(y1-y2);
    // Draw appropriate shape
    if (shape.equals("square")) {
    if (fillFlag) g.fillRect(upperLeftX,upperLeftY,width,width);
    else g.drawRect(upperLeftX,upperLeftY,width,width);
    else {
    if (shape.equals("rectangle")) {
    if (fillFlag) g.fillRect(upperLeftX,upperLeftY,width,height);
    else g.drawRect(upperLeftX,upperLeftY,width,height);
    else {
    if (shape.equals("circle")) {
    if (fillFlag) g.fillOval(upperLeftX,upperLeftY,width,width);
    else g.drawOval(upperLeftX,upperLeftY,width,width);
    else {
    if (fillFlag) g.fillOval(upperLeftX,upperLeftY,width,height);
    else g.drawOval(upperLeftX,upperLeftY,width,height);
    /* Mouse moved */
    public void mouseMoved(MouseEvent event) {
    displayMouseCoordinates(event.getX(),event.getY());
    /* Mouse dragged */
    public void mouseDragged(MouseEvent event) {
    Graphics g = getGraphics();
    x2=event.getX();
    y2=event.getY();
    x4=event.getX();
    y4=event.getY();
    displayMouseCoordinates(x1,y1);
    if (eraseFlag) g.clearRect(x2,y2,10,10);
    else {
    selectColor(g);
    if(drawShape.equals("brush")) g.drawLine(x3,y3,x4,y4);
    x3 = x4;
    y3 = y4;
    // ---------------------- WINDOW LISTENERS -------------------
    /* Blank methods for window listener */
    public void windowClosed(WindowEvent event) {}
    public void windowDeiconified(WindowEvent event) {}
    public void windowIconified(WindowEvent event) {}
    public void windowActivated(WindowEvent event) {}
    public void windowDeactivated(WindowEvent event) {}
    public void windowOpened(WindowEvent event) {}
    /* Window Closing */
    public void windowClosing(WindowEvent event) {
    if (event.getWindow() == about) {
    about.dispose();
    return;
    else System.exit(0);
    Code End
    Thanks again!
    class ziapp {
    /* Main method */
    public static void main(String[] args) {
    zipaint screen = new zipaint("Zi Paint Shop");
    screen.setSize(zipaint.WIDTH,zipaint.HEIGHT);
    screen.setVisible(true);

    First of all use the [url http://forum.java.sun.com/features.jsp#Formatting]Formatting Tags when posting code to the forum. I'm sure you don't code with every line left justified so we don't want to read unformatted code either.
    Hey everyone, I'm new to java and trying to convert this AWT program to SwingInstead of converting the whole program, start with something small, understand how it works and then convert a different part of the program. You can start by reading this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus.
    From a quick glance of your code it looks like you are not adding an ActionListener to your JMenuItems. You are adding them to the JMenu.
    Other observations:
    1) Don't mix AWT with Swing components. You are still using CheckBox
    2) Don't override paint(). When using Swing you should override paintComponent();
    3) Use LayoutManagers. Using a null layout does not allow for easy maintenance of the gui. Right now you are using 800 x 600 as your screen size. Most people are probably using at least 1024 x 768 screen sizes. When using LayoutManagers you would suggest component sizes by using setPreferredSize(), not setSize().

Maybe you are looking for

  • Error while running ant build script from cmd line -ORABPEL-01005

    Hi to all, I am newbie to BPEL, I did a sample application SyncHelloWorldBPEL application in Jdev and I deployed it application server everything looks good. When I ran the same ant build script from command line it throw me bunch of complation error

  • Error: while configuring logs for changes in infotype data

    Hi All, I am configuring the following Tables for maintain logs for changes in infotype data. V_T585A, V_T585B and V_T585C While configuring V_T585B, when i input * in 'field name' column it gives me an warning message " All data fields in **** infot

  • Error while Upgrading to PL10 from 2007A

    I got an error at the last database during the 'Pre-Upgrade Check'. The error says... Integrity check failed due to non-consecutive TransSeq on OINM for the same document row [SAP Note: 1344231]. The log file says.... 09/11/2010  14:18:43:154027     

  • Hyperlinks don't work, pause button on quicktime music doesn't work, help!

    Hi, This is my second time with I web, having created and maintained a site for 2 years I know a lot about the program. The thing that kills me with this program is that even when you think you do something right, there's a chance it just may not wor

  • Problem with portlets with XSLT generating dynamic portal compatible links

    Hi, We're using XSLT to transform XML data to HTML in a portlet. The problem is that the XML contains headlines and we need to create links to the complete article, which has to be displayed in the same portlet. How do I create a portal comaptible li