Results 1 to 4 of 4

Thread: Swing Interface

  1. #1
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Question Swing Interface

    Swing Interface-swordofthesamurai.pngHey users I am trying to create a Java swing gui which has a picture in the background and a dialogue box in the front of the image which shows the text output and so i can input my text in it instead of showing it in my JDE (i use eclipse)
    I have the Image done i just want some one to help me with the dialogue box and the input of my text
    Please if you can Could you show me the code I need to input


    Java Code:
    Java Code:
    package Samurai;
    import java.util.Scanner;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Image;
    import java.awt.PopupMenu;
    import java.awt.event.*;
    public class Samurai {
    
    	public static void main (String[] arg)  {
    	        //Displaying the Frame Created by MainScreenImage that Contains the Rules
    				new MainClassFrame();
    			//Displays a Dialogue Box Requesting for the User's Name from the Class Start Screen
    				startscreenimage frame = new startscreenimage();
    					frame.addWindowListener (new WindowAdapter() {
    						public void windowClosing(WindowEvent e) {
    							System.exit(0);
    						}
    					} );
    		
    			//VARIABLES ONLY SECTION
    		String nameofwarrior=null,cityname,hit,faith;
    		int nameofcity,cityexplore,i,k,villan,boss;
    		int Mob1[]={1,1},Player[]={0,0},ninjalord[]={24,4};
    		String astricks[]= {"*","**","***","****","*****","******","*******","********","*********","**********","***********","************","*************","**************","***************","****************","*****************"};
    		String chooseyourdestiny[]= {"C","H","O","O","S","E"," ","Y","O","U","R"," ","D","E","S","T","I","N","Y"};
    		//VARIABLES ONLY SECTION ENDS
    		
    		Scanner keyboard = new Scanner (System.in);
    		
    		System.out.println("Follow the instructions on screen.\n When asked for a answer please use Y for yes or N for no. \n Also to explore Press Enter.And to continue press enter.");
    		hit =keyboard.nextLine();
    		
    		System.out.println("Hey The Ol'e Wise Man Wishes to Know your NAME");
    		
    		nameofwarrior=keyboard.nextLine();
    		
    		if (nameofwarrior==null)
    		{
    			System.out.println("Please Type your Name");
    			nameofwarrior=keyboard.nextLine();
    		}
    
    		}
    		
    	}
    		class MainClassFrame extends JFrame{
    			/**Purpose: To Create a Frame for the Image from MainClassRules
    		     * Accepts: N/A
    		     * Returns:	N/A */
    			public MainClassFrame(){
    				add(new startscreenimage());
    				
    				setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		        setSize(680, 760);
    		        setLocationRelativeTo(null);
    		        setTitle("Samurai Game ");
    		        setVisible(true);
    		    }
    			/** @param args  */
    		    public static void main(String[] args) {
    		        new MainClassFrame();
    		    }
    		}
    			
    		class startscreenimage extends JPanel{
    			Image one;
    			public startscreenimage (){
    				ImageIcon ii = new ImageIcon(this.getClass().getResource("SwordOfTheSamurai.png"));
    				one= ii.getImage();
    			}
    			
    			public void addWindowListener(WindowAdapter windowAdapter) {
    				// TODO Auto-generated method stub
    				
    			}
    
    			public void paint (Graphics g){
    				Graphics2D g2d = (Graphics2D) g;
    				g2d.drawImage(one,0,0,null);
    			}
    			
    		}
    Last edited by Norm; 01-18-2012 at 10:02 PM. Reason: added code tags

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Swing Interface

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Default Re: Swing Interface

    oh i want like a box with all the text in it not a message box

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Swing Interface

    Quote Originally Posted by dharav View Post
    oh i want like a box with all the text in it not a message box
    Right. And how is that not a dialog? Perhaps you should mock up a picture of how you want your gui to look- that would be much more informative than the image you've already added.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM
  2. Swing Graphic interface
    By Daniel in forum AWT / Swing
    Replies: 2
    Last Post: 06-28-2007, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •