Results 1 to 3 of 3

Thread: Java 2d objects

  1. #1
    Egomeh is offline Member
    Join Date
    Feb 2009
    Location
    Denmark
    Posts
    2
    Rep Power
    0

    Default Java 2d objects

    Hi

    Im very new to Java, and im sorry if im posting in the frong place, but Java2d seemed too advanced for my problem.

    But anyway my problem is that I want to make label in a window/frame, but I want the label to be an object/class that is called when the window is created. Im not sure if what I've done is even close to be rigth, but here is the code:

    My label:
    Java Code:
    import javax.swing.*;
    
    public class Label{
    
        Label(){
            JLabel label = new JLabel("hello world");
            Frame.win.add(label);
        }
    }
    my window:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    
    public class Frame{
    
        Frame(String s, int x, int y){
            JFrame win = new JFrame(s);
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
            win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            win.setVisible(true);
            win.setSize(x, y);
            win.setLocation((dim.width/2), (dim.height/2));
        }
    }
    and in the main class, I've just written new Frame(bla bla); and new Label();

    The compiler just says that it cant find variable "win", but I cant understand why:confused:

    If anyone can help me I would appreciate the help very much.

    Thanks in advance

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Egomeh is offline Member
    Join Date
    Feb 2009
    Location
    Denmark
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2009, 05:25 PM
  2. Rotating objects in Java Applets
    By Unome in forum Java Applets
    Replies: 1
    Last Post: 10-17-2008, 08:35 AM
  3. Passing objects in Java
    By jbostjr in forum New To Java
    Replies: 1
    Last Post: 10-30-2007, 11:15 PM
  4. Passing objects in Java
    By jbostjr in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2007, 06:57 PM
  5. com objects in java
    By boy22 in forum New To Java
    Replies: 1
    Last Post: 07-14-2007, 07:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •