Jump to content

Outputting into a window in java

so i have the code i want perfect so it outputs a randomly generated statement followed by the question "would you like to go again" where if you type anything other than no it will go again

ill give a little example

 

 

import java.util.*;
 
public class Cards_against_humanity
{
     public static void main(String[] args)
     {
          Scanner jose = new Scanner(System.in);
          boolean again = true;
          while (again)
          {
               ArrayList<String> BlackCard = new ArrayList<>();

 

               /* code creating 90 various black cards*/

 

               System.out.println(BlackCard.get(((int)(Math.random()*90)+1))); //picks a random black card
               String s1 = new String();
               System.out.println("Would you like to go again?");
               s1 = jose.next();
               System.out.println();
               if (s1.equalsIgnoreCase("no"))
                    break;
          }
     }
}
 
so what i want to happen is when you run it, it outputs into a black window with white text outputting the random black card it selected but i want there to be 2 buttons where you can choose again or exit so yea any help would be nice :3

LG 34" 21:9 1440p

1080ti EVGA FTW3

i7 8700k @ 5GHz 1.3V Delidded

 

Link to comment
https://linustechtips.com/topic/58047-outputting-into-a-window-in-java/
Share on other sites

Link to post
Share on other sites

You best bet for creating GUIs in java is to have a look at Swing, in your case you should look at buttons and layout managers (you'll probably want to use BorderLayout and FlowLayout)

after you do it manually and understand how it works, look at eclipses GUI maker because good programmers like shortcuts. But not before you figure it out :P

Link to post
Share on other sites

Look into WindowBuilder for eclipse... will definitely help you with the buttons and layouts for them. As for implementing some code I would imagine you would want to add action listeners to your buttons and call methods when you click them. My Java experience is pretty limited but I did similar GUI/buttons stuff last year in my high-school comp sci course.

i5 3570k - MSI Z77 GD65 - 16GB Corsair Vengeance - Galaxy GTX 780 - Corsair AX650 - Custom CPU Loop - Corsair 650D - OCZ Agility 4 128GB - WD Black 640GB

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×