Click here to Skip to main content
15,886,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Im the begginer, and i realy want to proggramin in Java, but have a big problem.
I have a question:"How to show the random text after button is clicked.?"
All day I was searching on the internet and I founded only how to show the random number.
THANK YOU for every answer!
My code now:

//Button 1
JButton button1 = new JButton();
frame.add(panel);
panel.add(button1);
button1.setBounds(50,60,50,50);
panel.setLayout(null);
frame.setVisible(true);
button1.setText("1");

button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

JOptionPane.showMessageDialog(null, "This is first button");
}
});

What I have tried:

First i was set that show me random number when button is clicked. Then i was trying to convert integer to string. Ind a tried also with ArrayList but then i cannot show text when is button clicked.
I cannot convert this and I dont know where is a problem.
Posted
Updated 29-Dec-17 19:57pm
Comments
wseng 30-Dec-17 1:26am    
random text mean random letter ?

1 solution

You can generate a random string and then set your button text to that string:
java - How to generate a random alpha-numeric string? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900