Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- public class RandomCharactersTest {
- public static void main(String[] args)
- {
- RandomCharacters randomCharacters = new RandomCharacters();
- randomCharacters.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- randomCharacters.setSize(200,200);
- randomCharacters.setVisible(true);
- }
- }
- /////////////////////
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.security.SecureRandom;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- public class RandomCharacters extends JFrame
- {
- private JLabel randChar;
- private JTextField tf;
- private final JButton button;
- public RandomCharacters()
- {
- super("Random Characters");
- setLayout(new FlowLayout());
- tf = new JTextField(15);
- randChar = new JLabel("fire");
- add(randChar);
- button = new JButton("hi");
- add(button);
- while(true)
- {
- paintComponent();
- }
- }
- public void paintComponent()
- {
- SecureRandom r = new SecureRandom();
- switch(r.nextInt(7))
- {
- case 0: randChar.setForeground(Color.RED);
- break; //RED
- case 1: randChar.setForeground(Color.YELLOW);
- break; //YELLOW
- case 2: randChar.setForeground(Color.BLUE);
- break; //BLUE
- case 3: randChar.setForeground(Color.GREEN);
- break; //GREEN
- case 4: randChar.setForeground(Color.CYAN);
- break; //CYAN
- case 5: randChar.setForeground(Color.PINK);
- break; //PINK
- case 6: randChar.setForeground(Color.BLACK);
- //BLACK
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment