Im planing to have several Methods that will display the question and the answer choices to their coresponding labels and cmdButtons.
But somehow i get the error message "void is an invalid type for the variable" when i want to create my method below of my code (i commented the spot).
Maybe, someone can tell me what im doing wrong.
Thank you...
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class GameScreen extends JDialog {
JPanel frmGame = new JPanel();
JPanel frmQuestion = new JPanel();
JPanel frmLevel = new JPanel();
JLabel lblTitle = new JLabel ("Do you know...?");
JLabel lblRemember = new JLabel("Remeber, no mistake is allowed!");
JLabel lblPlayer = new JLabel("");
JLabel lblQuestion = new JLabel("");
JLabel lblPeso1 = new JLabel(" 10 Pesos");
JLabel lblPeso2 = new JLabel(" 20 Pesos");
JLabel lblPeso3 = new JLabel(" 30 Pesos");
JLabel lblPeso4 = new JLabel(" 40 Pesos");
JLabel lblPeso5 = new JLabel(" 50 Pesos");
JLabel lblPeso6 = new JLabel(" 60 Pesos");
JLabel lblPeso7 = new JLabel(" 70 Pesos");
JLabel lblPeso8 = new JLabel(" 80 Pesos");
JLabel lblPeso9 = new JLabel(" 90 Pesos");
JLabel lblPeso10 = new JLabel(" 100 Pesos");
JLabel lblImage6 = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\fackel_0010.GIF"));
JLabel lblImage7 = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\fackel_0010.GIF"));
JLabel lblReminder = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\mann_0007.GIF"));
JLabel lblPlayerIcon = new JLabel(new ImageIcon("D:\\Schule\\Java Projects\\Final Java2\\Nervous.GIF"));
JButton cmdAnswer1 = new JButton("A");
JButton cmdAnswer2 = new JButton("B");
JButton cmdAnswer3 = new JButton("C");
JButton cmdAnswer4 = new JButton("D");
JButton cmdBackChoose = new JButton("Back to Main Menu");
public GameScreen(String name) {
setSize(800,800);
setLocation(400,50);
setResizable(false);
setTitle("DO YOU KNOW...?");
setVisible(true);
frmGame.setLayout(null);
frmGame.setBackground(Color.BLACK);
frmQuestion.setLayout(null);
frmQuestion.setBackground(Color.BLUE);
frmQuestion.setBounds(150,150,500,200);
frmLevel.setLayout(null);
frmLevel.setBackground(Color.WHITE);
frmLevel.setBounds(660,400,130,300);
lblTitle.setFont(new Font("Arial", Font.BOLD, 30));
lblTitle.setForeground(Color.YELLOW);
lblTitle.setBounds(280,30,260,50);
lblQuestion.setBounds(150,150,500,200);
lblQuestion.setForeground(Color.YELLOW);
lblQuestion.setFont(new Font("Arial",Font.BOLD, 18));
lblPeso1.setBounds(660,670,130,30);
lblPeso1.setFont(new Font("Arial", Font.BOLD,22));
lblPeso2.setBounds(660,640,130,30);
lblPeso2.setFont(new Font("Arial", Font.BOLD,22));
lblPeso3.setBounds(660,610,130,30);
lblPeso3.setFont(new Font("Arial", Font.BOLD,22));
lblPeso4.setBounds(660,580,130,30);
lblPeso4.setFont(new Font("Arial", Font.BOLD,22));
lblPeso5.setBounds(660,550,130,30);
lblPeso5.setFont(new Font("Arial", Font.BOLD,22));
lblPeso6.setBounds(660,520,130,30);
lblPeso6.setFont(new Font("Arial", Font.BOLD,22));
lblPeso7.setBounds(660,490,130,30);
lblPeso7.setFont(new Font("Arial", Font.BOLD,22));
lblPeso8.setBounds(660,460,130,30);
lblPeso8.setFont(new Font("Arial", Font.BOLD,22));
lblPeso9.setBounds(660,430,130,30);
lblPeso9.setFont(new Font("Arial", Font.BOLD,22));
lblPeso10.setBounds(660,400,130,30);
lblPeso10.setFont(new Font("Arial", Font.BOLD,22));
lblReminder.setBounds(10,580,80,200);
lblRemember.setBounds(80,600,200,40);
lblRemember.setForeground(Color.RED);
lblPlayer.setBounds(360,740,100,40);
lblPlayer.setFont(new Font("Arial", Font.BOLD,18));
lblPlayer.setForeground(Color.YELLOW);
lblPlayer.setText(name);
lblPlayerIcon.setBounds(320,570,150,200);
cmdAnswer1.setBounds(225,400,150,50);
cmdAnswer2.setBounds(425,400,150,50);
cmdAnswer3.setBounds(225,500,150,50);
cmdAnswer4.setBounds(425,500,150,50);
cmdBackChoose.setBounds(640,730,150,40);
lblImage6.setBounds(100,245,50,110);
lblImage7.setBounds(660,245,50,110);
frmGame.add(lblPeso1);
frmGame.add(lblPeso2);
frmGame.add(lblPeso3);
frmGame.add(lblPeso4);
frmGame.add(lblPeso5);
frmGame.add(lblPeso6);
frmGame.add(lblPeso7);
frmGame.add(lblPeso8);
frmGame.add(lblPeso9);
frmGame.add(lblPeso10);
frmGame.add(lblPlayer);
frmGame.add(lblPlayerIcon);
frmGame.add(lblTitle);
frmGame.add(lblQuestion);
frmGame.add(frmQuestion);
frmGame.add(frmLevel);
frmGame.add(lblImage6);
frmGame.add(lblImage7);
frmGame.add(cmdAnswer1);
frmGame.add(cmdAnswer2);
frmGame.add(cmdAnswer3);
frmGame.add(cmdAnswer4);
frmGame.add(lblReminder);
frmGame.add(lblRemember);
frmGame.add(cmdBackChoose);
getContentPane().add(frmGame);
cmdBackChoose.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int result = JOptionPane.showConfirmDialog((Component) e.getSource(),"Do You Realy Want To Go Back To Main Menu?");
if (result == JOptionPane.YES_OPTION) {
dispose();
new ChoosingScreen().show();
} else if (result == JOptionPane.NO_OPTION) {
}
}});
/*
try {
// From file
Sequence sequence = MidiSystem.getSequence(new File("Addicted_To_Love.MIDI"));
// From URL
sequence = MidiSystem.getSequence(new URL("D:\\Schule\\Java Projects\\Final Java2\\Addicted_To_Love.MIDI"));
// Create a sequencer for the sequence
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
// Start playing
sequencer.start();
} catch (MalformedURLException e) {
} catch (IOException e) {
} catch (MidiUnavailableException e) {
} catch (InvalidMidiDataException e) {
}
*/
public void getQuestion { //the getQuestion creates the error
String q1 = "For what does JAVA stands for?";
String a1 = "answer1";
String a2 = "answer1";
String a3 = "answer1";
String a4 = "answer1";
lblQuestion.setText(q1);
cmdAnswer1.setText(a1);
cmdAnswer2.setText(a2);
cmdAnswer3.setText(a3);
cmdAnswer4.setText(a4);
}
}
}