This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-28 02:35:01

slayerrobe7
Scratcher
Registered: 2011-06-24
Posts: 500+

java help

im makeing a java program as part of a tutorial this assignment is to make a blank GUI with the title "SalutionMondo" my code is here

Code:

import javax.swing.*;

public class SalutonFrame extends JFrame {
    public SalutonFrame () {
        super("Saluton Mondo");
        setSize(350, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public static void main(String[] args) {
        SalutonFrame sal = new SalutonFrame();
    }
}

when i run the file nothing happens what is wrong


!!!When it comes to Scratch2.0 I am totally like freaking out!!!

Offline

 

#2 2012-04-28 02:45:56

slayerrobe7
Scratcher
Registered: 2011-06-24
Posts: 500+

Re: java help

never mind i found problem


!!!When it comes to Scratch2.0 I am totally like freaking out!!!

Offline

 

#3 2012-04-28 03:40:15

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: java help

You don't display the JFrame.
You have to write

Code:

        SalutonFrame sal = new SalutonFrame();
        sal.setVisible(true);

http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#4 2012-04-28 07:34:31

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: java help

Code:

//you may want java.awt.* as well, depends on your project
import javax.swing.*;

public class SalutonFrame extends JFrame {
    public SalutonFrame () {
        super("Saluton Mondo");
        setSize(350, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    
    public static void main(String[] args) {
        SalutonFrame sal = new SalutonFrame();
    }
    public void paint(Graphics g) {
         super.paint(g);
         //do all your painting code here
    }
}

Or, you can do this^

EDIT: wait you found the problem. nvm

Last edited by SJRCS_011 (2012-04-28 07:35:29)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

Board footer