Results 1 to 4 of 4
  1. #1
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Default Get "Frame"(?) as a methode

    Hello all
    I'm kind of new to java (kind of, i know the basics by now) :)
    Anyway, as our first script in school, we did a "frame" code, that gave out a box with text inside. that was just to see how a code looked like... Now, 1,5 years later, i'm still trying to figure how it works.

    Anyway, now i want to implent the old code as a method into another code. Is that possible?
    The code (Edited today, with lines i found on internet :p )
    Java Code:
    import java.awt.*;
    class test2 extends Frame
    		{
    			Font f;
    			Dimension ssize = Toolkit.getDefaultToolkit().getScreenSize();
    			int x = (int) (ssize.getWidth()) / 2;
      			int y = (int) (ssize.getHeight()) / 2;
    
    			test2()      //konstruktor för klassen test2
    			{
    				f=new Font("Sansserif",Font.BOLD,100);
    				setBackground(Color.black);
    				setSize(x*2, y);
    			}
    			
    			public void paint(Graphics g)
    			{
    				g.setFont(f);
    				g.setColor(Color.white);
    				g.drawString("Vakna", x, y);
    			}
    			
    			public static void vakna()
    			{
    				test2 t2 = new test2();
    				t2.setVisible(true);
    			}
    		}
    Anyone can help me implenitng in into another code?
    Java Code:
    		test2.vakna();
    doesn't seem to be enough
    :P
    ///Mattedatten

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    830
    Rep Power
    6

    Default

    Hi,
    Please try to read the sun tutorial and try to understand the basics.without knowing anjything if u try to copy and do,you will not gain
    knowledge.

    First of all,what u want to do? where is the comment in the code?

    -Regards
    Ramya
    Ramya:cool:

  3. #3
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Hi,
    Please try to read the sun tutorial and try to understand the basics.without knowing anjything if u try to copy and do,you will not gain
    knowledge.

    First of all,what u want to do? where is the comment in the code?

    -Regards
    Ramya
    I kind of know what i've edited, that the way i've learned most; During lessons, and asking for help with stuff that our teacher doesn't know how to do.

    The long code, test2, is made in a ways i haven't seen, we usually start codes like:
    Java Code:
    import javax.swing.*;
    
    public class StartCode
    {
    	public static void main (String [] arg) 
    	{
    		//Blabla
    	}	
    }
    And have more imports, methods and so on.
    What i want to do is use the test2 code as a methode, or make it pop up like a
    Java Code:
    JOptionPane.showMessageDialog(null, "BlaBla");
    I mean, I'm making a simple alarm-clock. And instead of
    Java Code:
    JOptionPane.showMessageDialog(null, "WAKE UP");
    I want something larger, and the frame thingy is good for this, because i can make it for half the screen. :p (And yes, i've set some sound into the code)

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

    Default

    1) Throw out that old code as it uses AWT and you really want to use Swing.
    2) Go through the Sun Swing tutorial as what you want to learn is the basics of creating GUIs, and this tutorial can show you this.

    Swing Tutorials

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 2
    Last Post: 10-08-2009, 11:28 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. "Jumble" or "Scramble" Program
    By Shadow22202 in forum Java Applets
    Replies: 8
    Last Post: 04-30-2008, 03:42 AM

Posting Permissions

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