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

#76 2012-02-17 18:16:25

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Java Official Topic

Java is awesome.
I'm a bit rusty though.  tongue

Offline

 

#77 2012-02-17 18:26:37

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

It's really easy to understand, but things like keyboard input and displaying graphics are kind of difficult. I'm installing LWJGL now to try to see what I can do with keyboard input.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#78 2012-02-19 08:21:41

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Java Official Topic

This is the first version of a program called "Reminders". Tell me what you think.

Code:

package main;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main {
    static JFrame frame;
    static JTextField f0;
    static JTextField f1;
    static JTextField f2;
    static JTextField f3;
    static Robot r;
    static int i;
    static java.awt.Font font = new java.awt.Font(Font.MONOSPACED, Font.PLAIN, 12);
    static String[] messages = {"Learn Minecraft modding.","Get Skirm to GET THE SERVER UP.","Enjoy being mod.","Do something besides Minecraft."};
    private static void createGUI(){
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice s = ge.getDefaultScreenDevice();
        int w = s.getDefaultConfiguration().getBounds().width;
        int h = s.getDefaultConfiguration().getBounds().height;
        frame = new JFrame();
        frame.setTitle("Reminders");
        frame.setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f0 = new JTextField();
        f1 = new JTextField();
        f2 = new JTextField();
        f3 = new JTextField();
        f3.setForeground(Color.WHITE);
        f2.setForeground(Color.LIGHT_GRAY);
        f1.setForeground(Color.GRAY);
        f0.setForeground(Color.DARK_GRAY);
        frame.add(ftf(f0));
        frame.add(ftf(f1));
        frame.add(ftf(f2));
        frame.add(ftf(f3));
        frame.pack();
        frame.setVisible(true);
        frame.setAlwaysOnTop(true);
        frame.setLocation(w-325, h-150);
        i = 0;
        while(true){
            f0.setText(f1.getText());
            f1.setText(f2.getText());
            f2.setText(f3.getText());
            f3.setText("");
            sleep(500L);
            for(int a = 0; a < messages[i].length(); a++){
                f3.setText(f3.getText()+messages[i].charAt(a));
                sleep(100L);
            }
            sleep(3000L);
            i = i+1;
            if (i>=messages.length){
                i = 0;
            }
            
            
        }

    }
    public static void main(String[] args){
        createGUI();
    }
    public Main(){
        
    }
    public static JTextField ftf(JTextField t){
        t.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        t.setPreferredSize(new Dimension(300,25));
        t.setBackground(Color.BLACK);
        t.setEditable(false);
        t.setFont(font);
        t.setSelectionColor(Color.WHITE);
        t.setSelectedTextColor(Color.BLACK);
        return t;
    }
    private static void sleep(long length){
        try {
            Thread.sleep(length);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

EDIT: Reimplemented it, so that it used threads. That seems to make it a whole lot more flexible.

Main.java

Code:

package main;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main{
    static JFrame frame = new JFrame();
    
    static JTextField f0;
    static JTextField f1;
    static JTextField f2;
    static JTextField f3;
    static JTextField time;
    static Robot r;
    static Thread c;
    static Thread t;
    static java.awt.Font font = new java.awt.Font(Font.MONOSPACED, Font.PLAIN, 12);
    static String[] messages = {"Learn Minecraft modding.","Get Skirm to GET THE SERVER UP.","Enjoy being mod.","Do something besides Minecraft."};
    private static void createGUI(){
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice s = ge.getDefaultScreenDevice();
        int w = s.getDefaultConfiguration().getBounds().width;
        int h = s.getDefaultConfiguration().getBounds().height;
        frame.setTitle("Reminders");
        frame.setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f0 = new JTextField();
        f1 = new JTextField();
        f2 = new JTextField();
        f3 = new JTextField();
        time = new JTextField();
        time.setForeground(Color.WHITE);
        f3.setForeground(Color.WHITE);
        f2.setForeground(Color.LIGHT_GRAY);
        f1.setForeground(Color.GRAY);
        f0.setForeground(Color.DARK_GRAY);
        frame.add(ftf(time));
        frame.add(ftf(f0));
        frame.add(ftf(f1));
        frame.add(ftf(f2));
        frame.add(ftf(f3));
        frame.pack();
        frame.setVisible(true);
        frame.setAlwaysOnTop(true);
        frame.setLocation(w-325, h-175);
        c = new Thread(new Changer());
        t = new Thread(new Time());
        t.start();
        c.start();

    }
    public static void main(String[] args){
        createGUI();
    }
    public Main(){
        
    }
    public static JTextField ftf(JTextField t){
        t.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        t.setPreferredSize(new Dimension(300,25));
        t.setBackground(Color.BLACK);
        t.setEditable(false);
        t.setFont(font);
        t.setSelectionColor(Color.WHITE);
        t.setSelectedTextColor(Color.BLACK);
        return t;
    }
    
    
}

Changer.java

Code:

package main;

public class Changer implements Runnable{

    @Override
    public void run() {
        int i = 0;
        while(true){
            Main.f0.setText(Main.f1.getText());
            Main.f1.setText(Main.f2.getText());
            Main.f2.setText(Main.f3.getText());
            Main.f3.setText("");
            sleep(500L);
            for(int a = 0; a < Main.messages[i].length(); a++){
                Main.f3.setText(Main.f3.getText()+Main.messages[i].charAt(a));
                sleep(100L);
            }
            sleep(3000L);
            i = i+1;
            if (i>=Main.messages.length){
                i = 0;
            }
            
            
        }
        
    }
    private static void sleep(long length){
        try {
            Thread.sleep(length);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Time.java

Code:

package main;

import java.util.Calendar;

public class Time implements Runnable{
    Calendar c;
    String[] ampm = {"AM","PM"};
    @Override
    public void run() {
        while(true){
            c = Calendar.getInstance();
            Main.time.setText(c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND)+" "+ampm[c.get(Calendar.AM_PM)]);
            sleep(1000L);    
            
        }
        
    }
    private static void sleep(long length){
        try {
            Thread.sleep(length);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Soon, I'll make the clock look more professional.

Last edited by wmays (2012-02-19 09:34:15)


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#79 2012-02-20 10:13:23

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Java Official Topic

Ok, really? No responses? I wish that someone would tell me what should be changed.


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#80 2012-02-20 13:26:01

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

This actually is really cool! Here's my thoughts...

It should probably read/write to a file to be able to save reminders.

I like the interface that it has, honestly. The only complaint I have about the interface is the color scheme of Windows 7 with the clear bars around the window.

I assume that for a later release it would have the ability to set custom reminders.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#81 2012-02-20 19:18:02

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Java Official Topic

16Skittles wrote:

This actually is really cool! Here's my thoughts...

It should probably read/write to a file to be able to save reminders.

I like the interface that it has, honestly. The only complaint I have about the interface is the color scheme of Windows 7 with the clear bars around the window.

I assume that for a later release it would have the ability to set custom reminders.

You read my mind!  tongue
I actually have already implemented that, I'm working out the kinks of some new features, and of course, I will prolly publish the final one. Just to say: it now has five classes, about 500 lines of code, and the clock is a bit better.


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#82 2012-02-22 07:59:55

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

My turn to look for help again, lol. Anyway, I'm trying to make a single class that paints all the graphics. (is that even a good idea? lol) When I call back the painter class, though, it doesn't repaint the graphics.

game.java

Code:

import java.awt.Color;
import javax.swing.*;


public class game {
        static JFrame game = new JFrame();
    public static void main(String args[]){
        //Defines the GAME loop boolean running. It manages the loop.
        boolean running = true;
        
        //creates the menu
        menu mainmenu = new menu();
        
        //calls the painter class so it can be used to draw graphics
        paint draw = new paint();
        
        //Variables used for the timer.
        long timemili, timemili2;
        
        //Creates the JFrame game
        //Set JFrame settings
        game.setSize(700, 450);
        game.setBackground(Color.BLACK);
        game.setTitle("Game Test");
        game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        //Render the logo
        draw.painter("caps.jpg", 200, 135);
        game.add(draw);
        game.setVisible(true);

        //The fade timer code
        timemili = System.currentTimeMillis();
        do{            timemili2 = System.currentTimeMillis();
            
        }while(timemili2 - timemili <5000);
        
        //Remove the logo
        game.setBackground(Color.WHITE);
        game.repaint();
        
        //show the menu
        mainmenu.mainmenu();
        
        //The game loop.
        while(running == true){
            draw.painter("loadlevel.jpg", 20, 30);
            draw.repaint();
            game.repaint();
        }
        
    }


}

paint.java

Code:

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class paint extends JPanel {
    int x = 0;
    int y = 0;
        
    private BufferedImage image;
    public void setPos(int imgx, int imgy){
        y=imgy;
        x=imgx;
    }
    public void painter(String path, int imgx, int imgy){
        y = imgy;
        x = imgx;
        try{
            image = ImageIO.read(paint.class.getResource(path));
        }
        catch(IOException e){
            System.out.println("Error finding image");
        }
        
    }
    
    public void paintComponent(Graphics g) {
        g.drawImage(image, x, y, null); 
        System.out.println(image);
    }
}

http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#83 2012-02-23 10:23:40

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

Disregard the above post, I'm looking into LWJGL and ditching my previous code. I have another question now...

Does anyone know if it is possible to compile code using LWJGL or another external library without using an IDE? I'm programming on two different computers (Home family laptop, my school laptop) and syncing my files with Dropbox, but it's annoying how Eclipse needs different entries for the location of the directory. I've solved that now, but I just would like to use notepad++ sometimes instead of waiting for Eclipse to start up.  hmm


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#84 2012-02-23 10:26:59

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Java Official Topic

16Skittles wrote:

My goal, however unreachable, is to get my skills up enough to make a simple game for Ludum Dare 23. It's April 20-23, so that gives me all of February, March, and lots of April to learn Java. It may be a horrible game, but it'll be a hack of a lot of fun! I'll need to hope I don't have baseball that weekend though...

Does ludum dare only accept java stuff or can it be other languages?


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#85 2012-02-23 10:29:29

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Java Official Topic

slinger wrote:

16Skittles wrote:

My goal, however unreachable, is to get my skills up enough to make a simple game for Ludum Dare 23. It's April 20-23, so that gives me all of February, March, and lots of April to learn Java. It may be a horrible game, but it'll be a hack of a lot of fun! I'll need to hope I don't have baseball that weekend though...

Does ludum dare only accept java stuff or can it be other languages?

It can be any language


Posts: 20000 - Show all posts

Offline

 

#86 2012-02-23 10:30:52

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Java Official Topic

Sweet, I may be a competitor then  tongue


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#87 2012-02-23 13:05:13

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

slinger wrote:

Sweet, I may be a competitor then  tongue

Good luck  smile
You can use any language, although it says that it is recommended to use Web/cross platform languages to get more users, therefore more votes.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#88 2012-02-23 13:20:17

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Java Official Topic

Yeah I use a cross-platform compiler so i'll be fine  tongue  You'll probably pwn me though as i'm really bad at making games. But by then i'll have learned opengl...
edit: good luck to you too  smile  When do we start developing?
edit2: dorn my fail, you only get 3 day 0_o well I'll have my work cut out for me.

Last edited by slinger (2012-02-23 13:22:00)


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#89 2012-02-23 13:37:31

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Java Official Topic

I use Eclipse. I'm also watching these and reading these and doing these at the appropriate time. They are very helpful.

Offline

 

#90 2012-02-23 15:55:30

transparent
Scratcher
Registered: 2011-04-19
Posts: 1000+

Re: Java Official Topic

I'm about to relearn after getting a book from the library about it. :3

CANT WAIT.


yes, yes i do.

Offline

 

#91 2012-02-23 17:58:28

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

w00t, just finished the ports tutorial. Chat program? Here I come!


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#92 2012-02-23 19:21:02

transparent
Scratcher
Registered: 2011-04-19
Posts: 1000+

Re: Java Official Topic

16Skittles wrote:

w00t, just finished the ports tutorial. Chat program? Here I come!

smile


yes, yes i do.

Offline

 

#93 2012-02-23 20:23:30

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

I will just say that working without an IDE is very humbling. I had started off with a ton of errors (11 on the server program, 7 on the client) that I had to try to troubleshoot, save, recompile, troubleshoot, etc. Chat program still not fully functional yet  tongue


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#94 2012-02-24 03:19:18

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Java Official Topic

16Skittles wrote:

w00t, just finished the ports tutorial. Chat program? Here I come!

Dang you're fast 0_o


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#95 2012-02-24 03:20:36

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Java Official Topic

16Skittles wrote:

I will just say that working without an IDE is very humbling. I had started off with a ton of errors (11 on the server program, 7 on the client) that I had to try to troubleshoot, save, recompile, troubleshoot, etc. Chat program still not fully functional yet  tongue

Yeah I hate ide errors D:


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#96 2012-02-24 17:40:45

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Java Official Topic

16Skittles wrote:

I will just say that working without an IDE is very humbling. I had started off with a ton of errors (11 on the server program, 7 on the client) that I had to try to troubleshoot, save, recompile, troubleshoot, etc. Chat program still not fully functional yet  tongue

Just saying, but I think you should use Eclipse. It really helps.


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#97 2012-02-24 17:51:42

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

wmays wrote:

16Skittles wrote:

I will just say that working without an IDE is very humbling. I had started off with a ton of errors (11 on the server program, 7 on the client) that I had to try to troubleshoot, save, recompile, troubleshoot, etc. Chat program still not fully functional yet  tongue

Just saying, but I think you should use Eclipse. It really helps.

I do use eclipse for most of my projects, but it is annoying sometimes when using multiple computers. I was just trying one project in notepad++ but I use Eclipse most of the time.


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#98 2012-02-26 09:57:23

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Java Official Topic

Woot for LWJGL! I now have all sorts of things like keyboard input and textures  big_smile


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#99 2012-02-26 14:32:18

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: Java Official Topic

Just wondering, but is it possible to define methods like for? Sort of like this...

Code:

repeat(10) {
//code to be executed
}

Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#100 2012-02-26 14:44:12

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: Java Official Topic

wmays wrote:

Just wondering, but is it possible to define methods like for? Sort of like this...

Code:

repeat(10) {
//code to be executed
}

Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).

I don't think there is.  hmm  I'd be happy to help as I know some tricks that might be helpful.


http://i45.tinypic.com/28rnqki.jpg

Offline

 

Board footer