1.11M Members

Any projects for the java beginner?

 
0
 

My ten year old has learnt quite a lot of java and wants a few BEGINNER projects. Any ideas?

 
0
 

Okay...

Get your (son/daughter?) to write a control component.
It should have the following buttons; Stop, Rewind (or Previous), Play/Pause, Fast Forward (or Next), Record.
It should have a display panel above the buttons to display time.
There should be a toggle to display either Time Elasped, or Time Remaining.

The reason that I suggested this project is...
I plan on doing the same thing on my vacation (in two weeks).
I am willing (after my vacation, I'm not going to steal their work) to critique the work.

 
0
 

Son.

Thanks, but that is far too advanced for him. He knows all of this:-
Objects
Instance variables
Bit of swing File io
Threads and networking(well, a little)
and more...
He DOES NOT KNOW user io.

 
0
 

user io is a lot easier to learn/code than File io

just let him take a look at the Scanner class and JOptionPane.

 
1
 

I know this sounds antiquated, but I learned a lot by writing a text adventure game -- like a Scott Adams text adventure game back in the early 1980s.

Something like that would expand his knowledge of user interaction and could be great for learning code re-use.

It could be done on the console or graphically or in an applet like at the link above.

 
2
 

I know this sounds antiquated

why would this sound antiquated?
no matter in what century they were born, all Olympic medal sprinters learned to crawl, then walk.

every one has to get to know the basics before going 'expert', so it's a good advice that 'll probably stay just that (good and solid advice) as long as people try to start learning java coding.

 
0
 

Tic-tac-toe - some Swing, some arrays, some logic... but nothing too hard.

 
1
 

I'd personally recommend a file/directory copy utility. This way, he'll get more acquainted with how the CLI clients work and get a taste of implementing a fun utility from scratch. The good thing is that this project can be beefed up if required by adding more options like the way a real copy command works. Bonus points for progress bar etc.

 
0
 

I gave him these ideas and here is his response.
7:30 pm : "Yay! Learnt Scanner!"
7:45 pm : Checked out the Scott Adams game
8:00 pm : Scott Adams--Hmm... how could I do that?
8:15 pm : tic-tac-toe:"EUREKA!!!! JLabels..."
8:30 pm : file copy-way too complicated

 
0
 

Hey, not hijacking this thread, (my son's doubt) if a jframe's content pane is set to a jpanel and a button is pressed. When it is pressed, can a new panel be made in the button's code and the NEW panel be set as the jframe's content pane?

 
0
 

JPanel myPanel = new JPanel();

onButtonPressed
myPanel = new JPanel();

something like that? seems possible to me, never actually coded it myself, though.

 
0
 

Hey, not hijacking this thread, (my son's doubt) if a jframe's content pane is set to a jpanel and a button is pressed. When it is pressed, can a new panel be made in the button's code and the NEW panel be set as the jframe's content pane?

Yes. But of you explain why, there may be a better approach (eg CardLayout)

 
0
 

no, this is what i meant:-

import java.io.*;
import java.awt.event.*;
public class --- implements Serializable, ActionListener {
JFrame frame;
public static void main(String[] args) {
new ---().go();
}
public void go() {
JPanel panelone = new JPanel();
frame = new JFrame("Double panel swing test");
frame.setContentPane(panelone);
JButton button = new JButton("Click me");
button.addActionListener(this);
panelone.add(button);
//other swing-related code...now for the actionPerformed()
}
public void actionPerformed(ActionEvent ev) {
//all...or...nothing...
JPanel panel2 = new JPanel();
frame.setContentPane(panel2);//THIS is what i meant
}
}
 
0
 

Yes, I understood that. You skeleton code is OK. But if you want to switch between multiple sets of content in the same frame, there are Swing classes to handle that for you, that's all. It just depends on where you-re going next with this...

 
0
 

8:00 pm : Scott Adams--Hmm... how could I do that?

Rock on!

One of the great benefits of something like that is also USER RESPONSE.
People evaluate what the program does rather than how it is written.

I sometimes get more excitement out of the coolness factor of the code more than what the code produces.

Getting feedback from users will serve him well.

 
0
 

A simple hangman game should be easy enough :) Find some simple games which can keep him excited

 
0
 

But if you want to switch between multiple sets of content in the same frame, there are Swing classes to handle that for you

import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Jpaneltest implements ActionListener {
JFrame frame;
JPanel panelone;
public static void main(String[] args) {
new Jpaneltest().go();
}
public void go() {
panelone = new JPanel();
frame = new JFrame("Double panel swing test");
frame.setContentPane(panelone);
JButton button = new JButton("Click me");
button.addActionListener(this);
panelone.add(button);
frame.setVisible(true);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ev) {
    JPanel pe = new JPanel();
    frame.setContentPane(pe);
}
}

How?
When I tested my code, all that happened:-
1. Click the button.
2. Went out of the button.
3. It still looks as if it has just been clicked, nothing happens either.

 
0
 

If you want to have multiple Jpanels and use a Button to show one at a time
the I think you should use CardLayout

 
0
 

can a cardLayout use a JButton instead of a JComboBox to navigate?

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article