Hey all, I've never made an applet before and I'm having a small problem. Basically, when I load my applet, the GUI comes up on a separate window (doesn't load within the applet window). Here's my code:
Here's the GUI class.
import java.awt.BorderLayout;
import java.io.File;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ListModel;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GUI extends javax.swing.JFrame {
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}
private JButton openB;
private JButton oddsB;
private JScrollPane jScrollPane1;
private JList jList1;
private JTextField fileText;
private Vector<String> jList1Objects;
/**
* Auto-generated main method to display this JFrame
*/
/*public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
GUI inst = new GUI();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}*/
public GUI() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
//Text field for file entry
fileText = new JTextField();
getContentPane().add(fileText);
fileText.setBounds(0, 0, 279, 25);
//Scroll Pane and jList1
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(0, 25, 150, 328);
{
jList1Objects = new Vector<String>();
jList1 = new JList(jList1Objects);
jScrollPane1.setViewportView(jList1);
}
//Open button and Odds button
openB = new JButton();
oddsB = new JButton();
getContentPane().add(oddsB);
getContentPane().add(openB);
oddsB.setText("Calculate Odds");
oddsB.setBounds(679, 109, 105, 353);
openB.setText("Open File");
openB.setBounds(279, 0, 99, 25);
//Open Button action
openB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
//Opens up hand history file to be read in
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("C:\\Program Files\\Full Tilt Poker\\HandHistory"));
int returnVal = fc.showOpenDialog(getContentPane());
if(returnVal == JFileChooser.APPROVE_OPTION) {
//Display file in text box
fileText.setText(fc.getSelectedFile().toString());
//TODO: Write function to read in file and add all Hands to jList1
//Recompile jList1
jList1Objects = new Vector<String>();
jList1Objects.add(fc.getSelectedFile().toString());
jList1 = new JList(jList1Objects);
jScrollPane1.setViewportView(jList1);
}
}
});
}
pack();
setSize(800, 800);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here's the class my HTML file calls:
import java.applet.Applet;
import javax.swing.JFrame;
public class Main extends Applet{
//Mainframe
//JFrame f = new JFrame();
public void init() {
GUI inst = new GUI();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
//f.setContentPane(inst.getContentPane());
}
public void start() {
System.out.println("Starting...");
}
public void stop() {
System.out.println("Stopping...");
}
}