Results 1 to 13 of 13
  1. #1
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Hello all. I'm not quite sure if this is the right forum for this, but I'm kind of at a loss at this point. I'm not sure if the technology recommended to me is really appropriate.

    I was on Stack Overflow (Can I Place a Program Written in the Java Programming Language on the Internet in a Way that Others can Run it for Free Without Security Issues? - Stack Overflow) asking about ways to put my text adventure online for free without massive security problems and someone recommended changing my GUI (which currently uses Swing and awt) into a GUI which uses a Java Server Page so I don't have to deploy an applet. I've since been scrambling to find tutorials and resources for how to do that, but it has not proved easy. Does anyone know any way I can swap out Swing and awt components for whatever it is that a JSP page uses to display content (I'm not even sure at this point if I can use the Java programming language to do that or if I need to learn something else)? Thank you so much for your time, a snippet of my current GUI code is shown below for reference:

    Java Code:
    public void init()
    {
    	
    	//Add the necessary content pane and set the layout.
    	JLayeredPane contentPane = new JLayeredPane();
    	contentPane.setLayout(null);
    	contentPane.setBackground(Color.DARK_GRAY);
    	
    	
    	//Set the content pane to the layered pane
    	this.setContentPane(contentPane);
    	
    	//Create Wounded Label
    	JLabel title = new JLabel();
    	title.setText("WOUNDED");
    	title.setFont(new Font("Courier", Font.BOLD, 48));
    	title.setVisible(true);
    	contentPane.add(title, new Integer(1));
    	
    	//Create the TextFeild for user input.
    	userInput = new TextField("", 15);
    	userInput.setText("Enter your choice here");
    	userInput.addActionListener(this);
    	userInput.setVisible(true);
    	contentPane.add(userInput, new Integer(3));
    	
    	//Get insets
    	Insets insets = contentPane.getInsets();
    	Dimension size;
    	
    	//Create the icon for the background label
    	try{
    	final ImageIcon wallPaper = new ImageIcon(getClass().getResource("/background.jpg"));	
    	JLabel background =  new JLabel(wallPaper);
    	contentPane.add(background, new Integer(0));
    	size = background.getSize();
    	background.setBounds(0, 0, 1200, 1200);
    	}
    	catch (Exception e)
    	{
    		System.out.println("Error, file not found");
    	}
    	
    	//Create the JTextArea for the display of story.
    	output = new JTextArea(40, 115);
    	scrollPane = new JScrollPane(output);
    	output.setFont(new Font("Courier", Font.PLAIN, 12));
    	output.setText(story);
    	output.setVisible(true);
    	scrollPane.setVisible(true);
    	contentPane.add(scrollPane, new Integer(3));
    	
    	//Uses absolute positioning to lay out the components
    	size = title.getPreferredSize();
    	title.setBounds(insets.left + 500, insets.top + 100, size.width, size.height);
    	size = userInput.getPreferredSize();
    	userInput.setBounds(insets.left + 530, insets.top + 1000, size.width, size.height);
    	size = output.getSize();
    	scrollPane.setBounds(insets.left + 200, insets.top + 200, 800, 800);
    	
    	
    	
    	
    	
    	/*
    	//Create the essential choose button to signal that
    	//the program should retrieve user input from userInput.
    	JButton chooseButton = new JButton();
    	chooseButton.setText("Choose");
    	chooseButton.addActionListener(this);
    	contentPane.add(chooseButton);
    	*/
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    There is no easy way to convert a Swing GUI to an HTML one, in general.
    Your is a simple text adventure with only a few parts to the screen, so this wouldn't be too tough, presuming you know the technologies you are planning on using.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by Tolls View Post
    There is no easy way to convert a Swing GUI to an HTML one, in general.
    Your is a simple text adventure with only a few parts to the screen, so this wouldn't be too tough, presuming you know the technologies you are planning on using.
    Unfortunately, I really don't. Would you be able to point me to a simple tutorial for making a page like this?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    It's not simple then.
    You'll need to learn a framework, either JSP/servlet or some other one.
    gimbal2 often recommends Wicket.
    But whichever one you were to choose, it's not a short journey.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,280
    Rep Power
    6

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Wicket, Play framework, Grails (although that's Groovy and not Java) - all excellent choices.

    Note that I consider Servlet / JSP to be a "no framework" solution since it does absolutely nothing for you :) As a first introduction into the world of Java web programming, that's not a bad thing. I consider learning Servlets before any web framework as important as learning Java programming on the command prompt before using an IDE.

    On that note:

    Free Online Version of Core Servlets and JavaServer Pages (Second Edition) in PDF
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by Tolls View Post
    It's not simple then.
    You'll need to learn a framework, either JSP/servlet or some other one.
    gimbal2 often recommends Wicket.
    But whichever one you were to choose, it's not a short journey.
    Thank you. I suppose I should just ask this bluntly then, as I've had this problem before. What framework could I learn that would still be around and in common use by the time I finished learning it?

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

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Why do you want to do this in the first place? Just package your game as an applet, webstart, and application, and then let people deploy it however they want. Seems like a ton of overkill to learn JavaEE just to convert an existing game to something more "webby".
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by gimbal2 View Post
    Note that I consider Servlet / JSP to be a "no framework" solution since it does absolutely nothing for you :)
    Indeed.
    I just couldn't think how to word it without typing too much.


    ...which I've now done...blast!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by KevinWorkman View Post
    Why do you want to do this in the first place? Just package your game as an applet, webstart, and application, and then let people deploy it however they want. Seems like a ton of overkill to learn JavaEE just to convert an existing game to something more "webby".
    So, here's the problem. I'm trying to get this game promoted on a website that will not promote file downloads unless they're super-duper secure, and there doesn't seem to be a way for an indie developer to get that sort of recognition if it's the first program they've put out.

    I tried putting it on a website and deploying it as an applet (http://firstprinceproductions.helioh...g/Wounded.html), but when people go to the page with a modern browser they get a scary warning message telling them what horribly insecure things applets are. I guess I could try to re-submit that game as a link to an applet, but I imagine I'll just get rejected before anyone actually plays my game, again.

    This game wasn't a java game to start actually, it was a C++ game. I've already learned another programming language to try and get people to actually be willing to play it. Now I'm starting to wonder whether I should have just tried to learn flash and done the whole thing there, as it seems to be the technology of choice for online games. Still, I made my stupid, stupid decision and now I have to live with ~5000 lines of code no one wants to run.

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

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Well, don't panic just yet. Firstly, you're in good company. Plenty of people make plenty of games in Java: Showcase - Java-Gaming.org

    There are more options other than deploying as an applet. Have you thought about deploying as a webstart application? Or a runnable jar? Or even a packaged executable?

    It's true that applets are rather un-pretty with Java's new warnings all over the place, but I really doubt the solution to your problem will be starting over with JSP.

    Where are you trying to promote your game? You might even consider going for a different host- Game Jolt allows applets (I think), and I even offer free Java hosting (although you admittedly won't magically get a million views without doing your own promotion) at StaticVoidGames.com.

    I'd recommend checking out the games at JGO and seeing how they're doing deployment, consider deploying as a webstart or runnable jar, or maybe just using a different site with less arbitrary rules.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,280
    Rep Power
    6

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by chaucer345 View Post
    Thank you. I suppose I should just ask this bluntly then, as I've had this problem before. What framework could I learn that would still be around and in common use by the time I finished learning it?
    Are my posts invisible again? Darnit!

    By the way I have to mention a huge disadvantage regarding Java web development: good luck hosting that stuff somewhere. I can name literally one in the Netherlands, as apposed to the 250 PHP hosting services (as an example). If you go down that route you may even consider forfeiting Java entirely and go for a *gulp* HTML 5 type of solution. I can't believe I recommended that.
    Last edited by gimbal2; 09-16-2013 at 08:52 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    39
    Rep Power
    0

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by KevinWorkman View Post
    Well, don't panic just yet. Firstly, you're in good company. Plenty of people make plenty of games in Java: Showcase - Java-Gaming.org

    There are more options other than deploying as an applet. Have you thought about deploying as a webstart application? Or a runnable jar? Or even a packaged executable?

    It's true that applets are rather un-pretty with Java's new warnings all over the place, but I really doubt the solution to your problem will be starting over with JSP.

    Where are you trying to promote your game? You might even consider going for a different host- Game Jolt allows applets (I think), and I even offer free Java hosting (although you admittedly won't magically get a million views without doing your own promotion) at StaticVoidGames.com.

    I'd recommend checking out the games at JGO and seeing how they're doing deployment, consider deploying as a webstart or runnable jar, or maybe just using a different site with less arbitrary rules.
    Wow, StaticVoidGames looks really cool. Not to derail the thread, but do you guys allow fan games?

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

    Default Re: Is it possible to convert this Swing/awt GUI into a JSP GUI? If so, how?

    Quote Originally Posted by chaucer345 View Post
    Wow, StaticVoidGames looks really cool. Not to derail the thread, but do you guys allow fan games?
    Thanks! It's definitely still a work in progress, but we've come a long way. I'm currently working on a huge overhaul, rewriting everything from scratch.

    Each member can set the source permissions for their own games, so the short answer is that it depends. When in doubt, leave a comment on a game you're interested in and ask permission!
    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. Convert applet from AWT to Swing
    By willp in forum New To Java
    Replies: 9
    Last Post: 09-04-2012, 01:08 AM
  2. Convert THE APPLET CODE TO SWING USING JPANEL
    By jammyjamsticy in forum AWT / Swing
    Replies: 2
    Last Post: 12-22-2011, 10:16 AM
  3. how to convert SWING GUI into exe format
    By santhosh_el in forum AWT / Swing
    Replies: 7
    Last Post: 04-04-2009, 01:36 PM
  4. how to convert xml to xsd
    By adi in forum XML
    Replies: 2
    Last Post: 02-12-2009, 03:43 PM
  5. 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

Posting Permissions

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