GUI: AWT vs Swing

I'm new at this and somebody told me that my interface looked hoakie and asked if Java can have GUIs that are as appealing as his VB interfaces. I just put basic swing components on my interface: buttons, text boxes, labels, etc...I didn't spend a whole lot of time figuring out how to change object attributes to possibly enhance my interface. As far as I understand swing is newer and better than AWT. Is this correct. Or do AWT interfaces look better? Can anybody direct me in this area and suggest the best way to get nice looking interfaces done with Java? Is this a drawback of Java?

Please don't cross post.

Similar Messages

  • Best way for gui programming? swing awt jfc swt ....

    hi,
    i have been programming java for some time but exclusively for web, servlets, jsp etc..
    but now i have to do some �real� gui�s. I have no gui experience , (ok I did some basic examples just to see how things work) but/and I�m not able to determine which way I should go.
    So I did some google search and read some threads here im forum on topics swing vs. awt (or so) and found lot of topics with lot of different opinions(some of them also a little bit out of date) so now im CONFUSED more then ever.
    I read people asking questions like :what is better awt or swing and then getting the perfect technical answers like :
    AWT components are NOT native components. AWT components are Java objects. Particular instances of AWT componets (Button, Label, etc.) MAY use peers to handle the rendering and event handling. Those peers do NOT have to be native components. And AWT components are NOT required to use peers for themselves at all.
    Or
    There are some significant differences between lightweight and heavyweight components. And, since all AWT components are heavyweight and all Swing components are lightweight (except for the top-level ones: JWindow, JFrame, JDialog, and JApplet), these differences become painfully apparent when you start mixing Swing components with AWT components.
    But I don�t care that much(at least not now) about this detail answers.
    I would simply like to know from some experienced gui guru, (due to the fact that we have 2005 and java 1.5) if u would like to learn gui in java quickly and know everything u know now which way would u choose:
    AWT
    JFC
    SWING
    SWT
    And which IDE would u use.
    I simply want to get quickly started and do some basic gui programming ,nothing special, but I would like to avoid that after weeks of doing one, then find out the was the wrong one and again learn the another one.
    TIA Nermin

    try swt vs swing and see what you think, its not really a decision someone else can make for you. as long as you don't try and mix the two, it should be a similar learning curve either way.

  • 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

  • How can I create a my own dialog in awt or swings

    How can I create a my own dialog in awt or swings instead of JDialog,Joption.
    if possible some example.
    Thanks in advance
    bhaskar

    hi,
    just use the building blocks of of GUI components and their methods. For examlpe u want to write a Font Dialog box,
    use Frame with lists , thers is classes by which u can pick the all fonts installes on ur system. Do appropriate programming to event handlers . On last in event handler of 'OK' button get the selected item from list and assign to wht u want thats all...........

  • 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().

  • Learn AWT before Swing?

    I have zero practical knowledge of Java GUI programming.
    Swing sits on top of AWT. Swing is easier than AWT. Yet, so as to understand Swing, and to be able to do things Swing might not be able to do, I am inclined to first only use AWT. Build a base on which to learn Swing.
    A counter argument would be, in my opinion, C vs. C++. While C++ sits on top of C, I don't see any benefit to learning pure C before C++. Further, I don't want things to be too difficult before making them easier regarding GUIs.
    Should the progression be: AWT then Swing? Swing then AWT then Swing? just Swing, and learn AWT if ever needed?

    I agree with the others, just learn swing and the parts of awt you need will just come along.
    But I want to add that using a GUI generator to create swing for you is very tempting, especially at first, but is the worst thing you can do to handicap yourself. I know you didn't mention them, so this is sort of comming from left field, but just saying avoid them until you really know swing.
    Also, how can you not see a benefit in learning C before C++? True C++ (even if not always practiced) is object oriented whereas true C is procedural. While OO programming is generally better, it is beneficial to understand procedural programming as well, and knowing both will only make you better as a programmer. But even more important is by never learning true C one never has a chance to learn just how powerful pointers are. Pointers are difficult to get your head around, but they are extreemly usefull, if you are one of the few rare people who can use them correctly and unlock their true power.
    Just Saying.
    JSG

  • 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.

  • Why is HeadlessException explicitly thrown in AWT and swing?

    Hi there,
    I just noticed that HeadlessException is explicitly thrown in some of the constructors in AWT and swing components since J2SE 1.4.
    Given that it's a RuntimeException (unchecked) it doesn't need to be included in the throws clause of the method or constructor.
    There also seems to be inconsistent application of it and inconsistent documentation in the javadoc comments.
    Is this a work in progress or did some refactoring go wrong?

    Most probably IE security settings preventing the js file to be executed. Replied in your other post:
    Unable to get property 'style' of undefined or null reference in sp.ui.dialog.debug.js
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • From awt to swing = classcastexception ?

    Hi !
    I am trying to move from awt to swing (j2sdk1.4.0_01)
    On recompiling with javac, no visible errors, nor when I try to debug with jdb.
    However when I try to load the class file, the java console tells me that I have a ClassCastException. Going thru the codes, I cannot see where I have type-casted anything wrong !
    Can someone point me in the right direction ?
    THX

    Hi !
    Tried some very simple codes...
    import javax.swing.*;
    public class TreeExample
    public static void main(String args[])
    JFrame frame = new JFrame("The Tree");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250,250);
    frame.show();
    jdb will run it and display it in an appletviewer
    window, but IE and Netscape will report a
    ClassCastException...
    At this point I think it might be some plug-ins ?The example you gave isn't an applet. Were you trying to run this exact code in a browser or was this just a sample? If you are trying to run this in a browser, it's probably trying to cast your TreeExample class to an Applet, which would explain the ClassCastException.

  • AWT vs Swing vs Applet

    Hi there,
    I'm currently writing a chess game and I'm wondering which would be best to use - AWT, Swing or an applet. I read that using Swing in an applet is not advisable as the classes that would need to be downloaded could be quite large and so take quite a long time. I've been writing it using AWT as I feel that it is fairly simple to change it to Swing or to an applet. What are your opinions on this?
    Many thanks!

    I'm currently writing a chess game and I'm wondering
    which would be best to use - AWT, Swing or an applet.Applets are not separate from AWT or Swing. The Applet class forms part of the AWT package, and JApplets are the Swing equivalent. If you were to use an Applet (or JApplet), you would still have to use AWT/Swing classes, such as Panel, Button etc. for the UI for your program, unless you want a mysterious magical grey box ;P
    I read that using Swing in an applet is not advisable
    as the classes that would need to be downloaded could
    be quite large and so take quite a long time. I don't have a lot of experience using the AWT classes, and use the newer Swing ones. I have heard Swing is easier to use, but many browsers do NOT support Swing classes as standard (particularly Internet Explorer), and require the plug-in, which is a fairly hefty download, especially on a dial-up.
    I've been writing it using AWT as I feel that it is fairly
    simple to change it to Swing or to an applet. What are
    your opinions on this?You say you are using AWT at the minute - are you writing the program as an application? If so, then I'm assuming you have the program running in a Frame, and to use the program as an applet, you would want to change your class from extending Frame to extending Applet. There shouldn't be a lot of change to code when adding components, but you will need to implement Applet methods (such as init()).
    Just note that in order to use the program on a webpage, it must be an applet. If you want to use the program as an applet, seeing as you have already started by using AWT, you might as well stick with it as you would be putting in effort to convert it into Swing only to restrict the potential audience.
    If you want the program to run as an application AND an applet, then the class extending Applet can have a main method, which creates a Frame, before adding a new instance of your applet and calling its init method.

  • AWT vs SWING and more

    1)Though the components used in awt and swing are similar what is the need for two seperate packages ?
    and
    2)what is the main usage of "getContentPane()" ?
    3)why do we use an appletviewer for executing applets provided the OS is Windows NT ..

    1)Though the components used in awt and swing are
    similar what is the need for two seperate packages ?AWT uses the native (heavyweight) components of the underlying Operating System. Actually a common (and small) subset of the provided components.
    In Swing the components a lightweight, there's no native component behind them, the components are painted by pure java code (sometimes sophisticated components). The swing applications thus can look and feel the same on all platforms.
    2)what is the main usage of "getContentPane()" ?When using swing you shouldn't add lightweight components to the window subclasses, only to the content pane.
    3)why do we use an appletviewer for executing applets
    provided the OS is Windows NT ..Did not understand.
    Kurta

  • 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

  • Database Connection to AWT and Swings

    How do we provide database connection to AWT and swing components?
    Is their any possibility to create database connection?
    Thanks in advance

    Just create an independent DAO class which does all the database/JDBC tasks.
    Then use this DAO class as you use every other class in your AWT/Swing application.

  • Can I build a GUI application with SWING only without [import java.awt.*;]

    I have seen several threads (in forums), books and tutorials about SWING and I see that they all mix SWING with AWT (I mean they import both Swing and AWT in their code).
    The conclusion that comes out is:
    It is good to learn about SWING and forget AWT as it won't be supported later. I have decided to do so, and I never include <<import java.awt.*;>> in my code.
    But I see that you cannot do much without <<import java.awt.*;>>. For example this line which changes the background color:
    <<frame.getContentPane().setBackground(Color.red)>>
    works only with <<import java.awt.*;>>. I have seen that codes in this and other forums import awt to change the background. Why is that?
    After all, I wonder, what can I do;
    My question is, can I change the background (and of course do all other things listener, buttons etc) without using <<import java.awt.*;>>.
    I would like to avoid using <<import java.awt.*;>> and using awt since my program will not work later.
    In addition, I believe there is no point to learn awt, which later will not exist.
    I know, I must have misunderstood something. I would appreceate it very much, if anyone could give me even a short answer.
    Thank you in advance,
    JMelsi

    Since swing is a layer on top of awt, AWT will exist for as long as swing does.
    If sun does ever remove AWT they will have to replace it something else swing can layer on to and you will probably only have to replace your import statements.
    The main difference is the way there drawn to the screen.
    You can do custom drawing on swing components but you can't on AWT.
    If your using a desktop PC system it's probably best to use swing just in case you wish to do some custom drawing.
    awt uses less memory than swing and is faster but swing can be extended. awt comes only as standard.
    Say for example you wish to implement a JButton with a ProgressBar below the button text, this can be done with swing!

  • AWT to SWING conversion - i am so lost!!!

    Hi,
    i am hoping somebody's expertise can help me. i am still relatively new to java and have created this class in java which has an AWT gui, that enables a user to click a "load" button, which the user can then select the jpeg they want to load and the class loads the picture in the canvas. Once i had created it i realised that i actually need to do it in SWING, but the problem is that i dont know how to convert this AWT class to a SWING based class. I have included the code below, and would really appreciate it if somebody can show me how to convert my code so that it is in SWING instead.
    Thank you for your help.
    kind regards,
    Very Confused One
    --------------------------START OF CODE [ImageDicer.java] --------------------------
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.util.*;
    public class ImageDicer extends Frame
    public static void main(String[] args)
    String fileName = "default";
    if (args.length > 0) fileName = args[0];
    new ImageDicer(fileName);
    private static final String kBanner = "ImageDicer v1.0";
    public ImageDicer(String fileName)
    super(kBanner);
    createUI();
    loadImage(fileName);
    setVisible(true);
    private Panel mControlPanel;
    private void createUI()
    setFont(new Font("Serif", Font.PLAIN, 12));
    setLayout(new BorderLayout());
    final Label statusLabel = new Label("Welcome to " + kBanner + ".");
    Button loadButton = new Button("Load...");
    loadButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    FileDialog fd = new FileDialog(ImageDicer.this);
    fd.show();
    if (fd.getFile() == null) return;
    String path = fd.getDirectory() + fd.getFile();
    loadImage(path);
    mControlPanel = new Panel();
    mControlPanel.add(loadButton);
    mControlPanel.add(statusLabel);
    add(mControlPanel, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    dispose();
    System.exit(0);
    private void adjustToImageSize()
    if (!isDisplayable()) addNotify(); // Do this to get valid Insets.
    Insets insets = getInsets();
    int w = mBufferedImage.getWidth() + insets.left + insets.right;
    int h = mBufferedImage.getHeight() + insets.top + insets.bottom;
    h += mControlPanel.getPreferredSize().height;
    setSize(w, h);
    private void center()
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    setLocation(x, y);
    private BufferedImage mBufferedImage;
    private void loadImage(String fileName)
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try { mt.waitForID(0); }
    catch (InterruptedException ie) { return; }
    if (mt.isErrorID(0)) return;
    mBufferedImage = new BufferedImage(image.getWidth(null),
    image.getHeight(null),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = mBufferedImage.createGraphics();
    g2.drawImage(image, null, null);
    adjustToImageSize();
    center();
    validate();
    repaint();
    setTitle(kBanner + ": " + fileName);
    public void paint(Graphics g)
    if (mBufferedImage == null) return;
    Insets insets = getInsets();
    g.drawImage(mBufferedImage, insets.left, insets.top, null);
    --------------------------END OF CODE [ImageDicer.java] --------------------------

    Thanks again for your assistance. The class manages to compile now but there seems to be a bug in the program. Everytime i run the class, the window loads, but the load button does not appear. It only appears when you click aimlessly at the bottom of the window until u luckily click on it. i cannot understand why this is happening :s
    Again i am greatful for your help.
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.ImageIO;
    import java.net.*;
    import javax.swing.filechooser.*;
    public class ImageDicer extends JFrame
    String kBanner = "ImageDicer v1.0";
    JPanel mControlPanel;
    JLabel statusLabel;
    JButton loadButton;
    public BufferedImage mBufferedImage;
    public ImageDicer(String fileName)
    { Container pane=getContentPane();
         setTitle(kBanner);
         pane.setLayout(new BorderLayout());
    statusLabel = new JLabel("Welcome to " + kBanner + ".");
    loadButton = new JButton("Load...");
    loadButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    {  JFileChooser fd = new JFileChooser();
         int returnVal=fd.showOpenDialog(ImageDicer.this);
              if(returnVal==JFileChooser.APPROVE_OPTION)
                   {if (fd.getSelectedFile() == null)
                              {return;}
                                  File file=fd.getSelectedFile();
                                  String path=(String)file.getPath();
                                  loadImage(path);
    mControlPanel = new JPanel();
         mControlPanel.add(loadButton);
         mControlPanel.add(statusLabel);
    pane.add( BorderLayout.SOUTH, mControlPanel);
    public void adjustToImageSize()
    if (!isDisplayable()) addNotify(); // Do this to get valid Insets.
    Insets insets = getInsets();
    int w = mBufferedImage.getWidth() + insets.left + insets.right;
    int h = mBufferedImage.getHeight() + insets.top + insets.bottom;
    h += mControlPanel.getPreferredSize().height;
    setSize(w, h);
    public void center()
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    setLocation(x, y);
    public void loadImage(String fileName)
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try { mt.waitForID(0); }
    catch (InterruptedException ie) { return; }
    if (mt.isErrorID(0)) return;
    mBufferedImage = new BufferedImage(image.getWidth(null),
    image.getHeight(null),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = mBufferedImage.createGraphics();
    g2.drawImage(image, null, null);
    adjustToImageSize();
    center();
    validate();
    repaint();
    setTitle(kBanner + ": " + fileName);
    public void paint(Graphics g)
    if (mBufferedImage == null) return;
    Insets insets = getInsets();
    g.drawImage(mBufferedImage, insets.left, insets.top, null);
    public static void main(String[] args)
    String fileName = "default";
    if (args.length > 0) fileName = args[0];
    ImageDicer img=new ImageDicer(fileName);
    img.setSize(800,600);
    img.show();
    }

Maybe you are looking for

  • How to add additional tab or fields in ME21n

    Hi all. I included some fields in EKKO table. I want to add these fields in ME21n, ME22n, ME23n Header screens. How to add? I can't find screen exit and user exit. Plz, let me know how to do in detail. Regards, nam Message was edited by:         Kil

  • Post an incoming payment ( check ) against an invoice

    Hi I am trying to post an incoming payment ( cheque ) against an invoice. I keep getting no matching records found ( odbc error -2028 ) Has anyone got a simple example I could use as a comparison please ? Thanks Regards Andy

  • Why does RT 2011 Sp1 tell me that I need a newer version to run an app?

    After installing RT 2011 SP1 on a laptop, I get an error that I need a newer version of Run time when i try to run an application created from LV 2011 SP1. Any ideas why?

  • How to get out of screen sharing

    how do you get back to video chat when you are in screen sharing..........when I end screen sharing, I lose the video connection.............there has to be a way to get to video chatting...........right?

  • XMLTYPE  Updation

    Hi, We can extract data from a stored procedure parameter of type XMLType using the function xslprocessor.valueOf() Can we update the contents of XMLType in Oracle using a function.If any body knows please help me Regards, Aneesh Kumar.P