PDA

View Full Version : HTML and Java GUIs D:



Jessweeee♪
01-26-2009, 10:53 PM
Help! Is there a way to put a GUI coded in Java into a web page without turning it into an applet?

We're working on this project at school. I had to tell the programmers I only knew how to put applets in, and they're having a little trouble turning it into one x.x

Flying Mullet
01-26-2009, 11:11 PM
Most likely not. Java GUI's (AWT and Swing) and HTML are completely different languages with completely different architectures.

o_O
01-26-2009, 11:15 PM
Unfortunately there isn't, as far as I know. You could include limited Java functionality in the GUI of the web page by using JSP with the Tomcat webserver but that wouldn't allow for the creation of JPanels and JFrames and whatnot. As long as the main class of the Java program extends the Applet superclass then there shouldn't be a lot more to change though. Perhaps if you had more detail on what issues they're having somebody here could help? :p

NeoTifa
01-29-2009, 05:58 PM
No, applets were made spacifically for this reason. :\

Jessweeee♪
02-04-2009, 05:20 PM
Okay, so this is what it looks like so far.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class MakingBank extends JApplet
{

public static void main(String[] args)
{

JFrame frame = new JFrame();
JPanel panel2 = new JPanel();
panel.add(name);
panel.add(nameIGuess);
panel.add(address);
panel.add(place);

final PressButton john = new PressButton();




panel.add(pine, BorderLayout.CENTER);
panel.add(fresh);
panel.add(pine2, BorderLayout.CENTER);
panel.add(fresh2);
panel.add(pine3, BorderLayout.CENTER);
panel.add(fresh3);
panel.add(pine4, BorderLayout.CENTER);
panel.add(fresh4);
panel.add(enter);
panel.add(reciept);

panel.setBackground(background);
frame.add(panel);
frame.setTitle("Bank");
enter.addActionListener(PressButton.listener);





fresh.setText("0");
fresh2.setText("0");
fresh3.setText("0");
fresh4.setText("0");

reciept.setEditable(false);

place.setBackground(Color.WHITE);
nameIGuess.setBackground(Color.WHITE);
fresh.setBackground(Color.WHITE);
fresh2.setBackground(Color.WHITE);
fresh3.setBackground(Color.WHITE);
fresh4.setBackground(Color.WHITE);
reciept.setBackground(Color.WHITE);

frame.setSize(650, 650);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}
public static Color background = Color.GRAY;


public static final JLabel name = new JLabel("Name: ");
public static final JTextField place = new JTextField(50);
public static final JLabel address = new JLabel("Address: ");
public static final JTextArea reciept = new JTextArea(10, 30);

public static final JTextField nameIGuess = new JTextField(50);
public static final JLabel pine = new JLabel("Pine Tree Air Freshener ($9.99): ");
public static JTextField fresh = new JTextField(50);
public static final JLabel pine2 = new JLabel("Pine Tree Cologne ($10.99): ");
public static final JTextField fresh2 = new JTextField(50);
public static final JLabel pine3 = new JLabel("Pine Tree Puppets ($5.99): ");
public static final JTextField fresh3 = new JTextField(50);
public static final JLabel pine4 = new JLabel("Pine Tree Planter ($25.99): ");
public static final JTextField fresh4 = new JTextField(50);
public static final JPanel panelproduct = new JPanel();
public static final JPanel panel = new JPanel();

public static final JButton enter = new JButton("Enter");

}


We can't get it to run as an applet S:

Is there something we're using that just doesn't work that way?

NeoTifa
02-04-2009, 08:56 PM
Why pine? XD What IDE are you using?

Baloki
02-04-2009, 10:16 PM
I remember once there was a way of doing it via Active-X, drawback is it's then browser dependent, but it's been so long since I touched Java I can't really remember much useful :/

Jessweeee♪
02-04-2009, 11:40 PM
Oh, it's like, selling pine scented air fresheners. The fake company we were "working" for during that particular assignment sells them. So we've turned it in and I don't know if they ever figured it out or not, but it's really bugging me and now I just want to know xD

o_O
02-05-2009, 01:16 AM
The structure of the MakingBank class is all wrong - it's been written as a regular standalone Java application. It'll run by itself, but as soon as you try to run it as an applet the Java VM doesn't know what to do with it. Here's a few things that need to change:

- Currently the class declares only a main() method. Applets should declare the init(), start(), stop() and destroy() methods. init() is called when the applet is loaded and start() is called when it first becomes visible (after init()).
- Also, an ActionListener is used in the main() method of the class, but it doesn't implement the ActionListener interface in the class definition. You'd need to have your class definition as "public class MakingBank extends JApplet implements ActionListener" if you are going to want it to do anything dynamically.
- If you are wanting to be able to click on stuff then you probably should include the MouseListener interface as well: "public class MakingBank extends JApplet implements ActionListener,MouseListener"
- Implementing ActionListener and MouseListener also means you'll have to declare the associated methods for each interface. For ActionListener it's actionPerformed() and for MouseListener they are mouseClicked(), mouseEntered(), mouseExited(), mousePressed(), mouseReleased().
- I'm assuming that the developer of this code has written a helper class "PressButton", because it doesn't seem to exist in any official APIs. :p

Hopefully that helps whoever it needs to - the whole program needs quite an overhaul!

Jessweeee♪
02-05-2009, 01:19 AM
Yeah, we're all newbs xD

This should help, thanks Face :</>D!

NeoTifa
02-08-2009, 03:46 PM
I knew it looked funny, but I really didn't feel like looking through it. Yea, there is no main method, just init(). Have you read any books on java?

Jessweeee♪
02-08-2009, 06:55 PM
We have textbooks, but I don't understand any of it x.x

NeoTifa
02-09-2009, 12:20 AM
Go to the website in my userbar. They have tons of tutorials for this kind of thing. ^___________^