Mój kod wypisuje wiele odpowiedzi, gdy chcę mieć tylko jeden naraz, czy możesz mi pomóc, aby wydrukować tylko jeden na raz?Wydrukuj jedną losową odpowiedź z sześciu
Chciałbym również pomóc, aby po uruchomieniu był przycisk, który można nacisnąć, aby odświeżyć stronę, tworząc nowe pytanie, z każdego z sześciu.
package ScienceRevision;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Image extends JFrame {
Font font = new Font("Arial", Font.BOLD | Font.ITALIC, 30);
public Image(){
//Game Properties
setTitle("WheelOP");
//setSize(750, 750);
setResizable(false);
setBackground(Color.CYAN);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.setFont(font);
g.setColor(Color.RED);
Random rand = new Random();
int result = rand.nextInt(6);
if (result == 0){
g.drawString("Cell Wall Definition", 100, 100);
}
else if (result == 1){
g.drawString("Vacuole Definition", 100, 100);
}
else if (result == 2){
g.drawString("Choroplast Definition", 100, 100);
}
else if (result == 3){
g.drawString("Nucleus Definition", 100, 100);
}
else if (result == 4){
g.drawString("Cell Membrane Definition", 100, 100);
}
else if (result == 5){
g.drawString("Cytoplasm Definition", 100, 100);
}
}
public void paintcomponent (Graphics g){
}
public static void main(String[] args){
JFrame jframe = new Image();
jframe.setSize(750,750);
jframe.setVisible(true);
jframe.getContentPane().setBackground(Color.CYAN);
jframe.setVisible(true);
}
Nadal maluje wiele odpowiedzi na raz. –
Czy usunąłeś zarówno 'setSize (750, 750); jak i' setVisible (true); 'z konstruktora? – gonzo
Tak. public static void main (String [] args) { JFrame jframe = new Image(); jframe.setSize (750,750); jframe.setVisible (true); jframe.getContentPane(). SetBackground (Color.CYAN); jframe.setVisible (true); } –