I'm trying to create a name generator that generates names by random. Now when i click the button, it generates a name, but it shows up in the Eclipse console and not in the same window as the button, which is what I want it to do. Eventually I would like to be able to have a specific picture for for the button and for the background (window/frame). Also, as a bonus I'm hoping to add a bit of music to it that can play in the background once you open the app. Now, I'm fairly new to java and I've only watched a couple of tutorials, but it's gotten me this far and hopefully I can learn a thing or two from one of you guys. So please be kind, Best regards leal.
import javax.swing.*;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class ClanNameGenerator {
public static void main (String[] args){
JFrame frame = new JFrame("ExETesT");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,350);
JPanel panel = new JPanel ();
frame.add(panel);
JButton button = new JButton("Click me");
panel.add(button);
button.addActionListener(new Action());
}
static class Action implements ActionListener{
public void actionPerformed (ActionEvent e){
String[] names = {"test", "Zero", "Club", "Moonkys", "znakes", "SeamOnster", "dnktwhm", "Rambo", "OmG", "siste"};
String[] names2 = {"Ylos", "zzzzz", "sdsd", "OK"};
String[] names3 = {"Hei", "ok", "jadd", "så drar vi", "det var det"};
int random = (int) (Math.random()*names.length);
int random2 = (int) (Math.random()*names2.length);
int random3 = (int) (Math.random()*names3.length);
System.out.println("Your clan name is: " + names[random] +" "+ names2[random2] +" "+ names3[random3]);
}
}
}