Java is awesome.
I'm a bit rusty though.
Offline
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.
Offline
This is the first version of a program called "Reminders". Tell me what you think.
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
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
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
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)
Offline
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.
Offline
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!
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.
Offline
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
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
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); } }
Offline
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.
Offline
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?
Offline
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
Offline
slinger wrote:
Sweet, I may be a competitor then
Good luck
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.
Offline
Yeah I use a cross-platform compiler so i'll be fine 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 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)
Offline
I use Eclipse. I'm also watching these and reading these and doing these at the appropriate time. They are very helpful.
Offline
I'm about to relearn after getting a book from the library about it. :3
CANT WAIT.
Offline
w00t, just finished the ports tutorial. Chat program? Here I come!
Offline
16Skittles wrote:
w00t, just finished the ports tutorial. Chat program? Here I come!
Offline
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
Offline
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
Yeah I hate ide errors D:
Offline
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
Just saying, but I think you should use Eclipse. It really helps.
Offline
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
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.
Offline
Woot for LWJGL! I now have all sorts of things like keyboard input and textures
Offline
Just wondering, but is it possible to define methods like for? Sort of like this...
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).
Offline
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. I'd be happy to help as I know some tricks that might be helpful.
Offline