|
-
Oct 10th, 2007, 10:28 AM
#1
Thread Starter
New Member
Dia panel, how?
Hello everybody,
My english is not very well but i will try to make the best of it
I'm working about a Java Application for a school project. I will make a presentation with buttons to switch to the next screen. First the can select the language between Netherlands or English (to click on the flag) and then follows the presentation in the language the have chosen. Till now i have made the following code:
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EventApplicatie2 extends JFrame {
private JPanel paneel;
public EventApplicatie2() {
paneel = new WelkomstPaneel();
setContentPane( paneel );
}
public static void main( String args[] ) {
JFrame frame = new EventApplicatie2();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize( 400, 200 );
frame.setLocation( 200, 200 );
frame.setSize( 450, 400 );
frame.setTitle( "EventApplicatie" );
frame.setVisible( true );
}
}
And:
Code:
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WelkomstPaneel extends JPanel {
private JLabel Label, Label2;
private JButton knop, knop1;
private boolean JPG;
private ImageIcon JPG1, JPG2;
public WelkomstPaneel() {
JPG1 = new ImageIcon( "EngelandVlag.JPG" );
JPG2 = new ImageIcon( "NederlandseVlag.JPG" );
setLayout( null );
Label = new JLabel( "Hartelijk welkom bij Nemo / Welcome to Nemo");
Label.setBounds( 80, 50, 500, 20);
Label2 = new JLabel( "Selecteer uw taal / Choose your laguage");
Label2.setBounds( 80, 70, 500, 20);
knop = new JButton( "Ga verder" );
knop.addActionListener( new KnopHandler() );
knop.setBounds( 100, 80, 120, 20 );
knop1 = new JButton( "Go" );
knop.setBounds( 100, 200, 120, 20 );
add( Label );
add( Label2 );
add( knop );
add( knop1 );
}
public void paintComponent( Graphics g ){
super.paintComponent( g );
JPG2.paintIcon( this, g, 100, 100 );
JPG1.paintIcon( this, g, 230, 100 );
}
class KnopHandler implements ActionListener {
public void actionPerformed( ActionEvent e ){
if( e.getSource() == knop )
Label.setText( "Selecteer uw taal" );
if( e.getSource() == knop1 )
Label.setText( "Choose youre language" );
}
}
}
Only this code is not enough and i don't how to make the rest of the program.
This is my result till now:
Last edited by MarkB1986; Oct 10th, 2007 at 12:53 PM.
-
Oct 10th, 2007, 03:00 PM
#2
Re: Dia panel, how?
You should start by painting the flags in buttons or panels instead of just drawing them on the form, then if a button you should add an action listener to handle the click event.. then you know what to do I guess
Code:
JButton btnEng=new JButton(JPG1);
btnEng.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Move to the next frame
}
});
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 10th, 2007, 03:50 PM
#3
Thread Starter
New Member
Re: Dia panel, how?
Ok, the buttons are working with the flag inside. The only thing i don't understand is how i go to the next screen. Do i have to make different classes for each screen? Or can i put it in one class.. I have a book about java but the chapter User Applications is not so extensive.
-
Oct 10th, 2007, 04:04 PM
#4
Re: Dia panel, how?
You can always read another book if you're interested, but if you don't have time or don't like reading. Then the answer is "There is no correct answer". This is totally up to you. you can do it whatever way that you'd like.
Of course using multiple classes (Panels) seems the best organized way to me, but again it's all up to you
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 11th, 2007, 02:38 AM
#5
Thread Starter
New Member
Re: Dia panel, how?
 Originally Posted by ComputerJy
Of course using multiple classes (Panels) seems the best organized way to me, but again it's all up to you
Ok, i think this option is the best. So i make different classes for the screens but i don't now how to link the screens together. Example: i press the button, then i make a actionlistener when i say: go to screen (class) ".."
How do i set this up? I don't now the code for this..
Code:
public void actionPerformed(ActionEvent e) {
// Move to the next frame
-
Oct 11th, 2007, 08:53 AM
#6
Re: Dia panel, how?
Code:
public class WelkomstPaneel extends JPanel {
private ImageIcon JPG1;
private final int panelsCount = 10;
private Panel[] myPanels = new Panel[panelsCount];
private int currentPanel;
public WelkomstPaneel() {
JButton btnEng = new JButton(JPG1);
for (int i = 0; i < panelsCount; i++) {
myPanels[i] = new Panel();
}
btnEng.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
moveNext();
}
});
}
public void moveNext() {
myPanels[currentPanel].setVisible(false);
myPanels[++currentPanel].setVisible(true);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|