Hey all,
I have a JApplet that runs in browser and I can't get it to create a new JFrame popup when a button is clicked. It works fine in my IDE (Eclipse) but not when I upload it. Here's the code for the JFrame I'm trying to create:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.jdesktop.swingx.*;
public class SchedWind {
private String selectedDate;
private PHPHandler phpMain;
private ResponseObj[] serverPHPresponse;
private final JLabel hotStatus;
public SchedWind() {
hotStatus = new JLabel("Waiting for user...");
serverPHPresponse = null;
selectedDate = null;
phpMain = new PHPHandler();
showGUI();
}
public void showGUI() {
final JFrame frame = new JFrame("Schedule");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setResizable(false);
GridBagLayout gLayout = new GridBagLayout();
frame.setLayout(gLayout);
GridBagConstraints c = new GridBagConstraints();
hotStatus.setForeground(Color.BLUE);
hotStatus.setVerticalAlignment(JLabel.CENTER);
hotStatus.setHorizontalAlignment(JLabel.CENTER);
JLabel selectDayLabel = new JLabel("Please select day:");
selectDayLabel.setOpaque(false);
selectDayLabel.setPreferredSize(new Dimension(170,30));
selectDayLabel.setHorizontalAlignment(JLabel.CENTER);
selectDayLabel.setVerticalAlignment(JLabel.CENTER);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
frame.add(selectDayLabel, c);
final JXDatePicker datePicker = new JXDatePicker();
datePicker.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectedDate = datePicker.getDate().toString();
//System.out.println(selectedDate);
}
});
c.gridx = 1;
c.gridy = 0;
frame.add(datePicker, c);
JButton grabSched = new JButton("OK");
c.gridx = 0;
c.gridy = 1;
c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(20,10,0,0);
grabSched.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(selectedDate == null) {
hotStatus.setText("Please enter a date.");
hotStatus.setForeground(Color.RED);
}
else {
hotStatus.setText("Contacting server...");
hotStatus.setForeground(Color.BLUE);
//System.out.println(selectedDate);
grabSchedFromServer();
}
}
});
frame.add(grabSched, c);
JButton cancel = new JButton("Cancel");
c.gridx = 1;
c.gridy = 1;
frame.add(cancel, c);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 2;
frame.add(hotStatus, c);
frame.pack();
frame.setVisible(true);
}
protected void grabSchedFromServer() {
String[] conArr = selectedDate.split(" ");
String mo = conArr[1];
String con = conArr[5] + "-";
if(mo.equals("Jan"))
con += "01-";
else if(mo.equals("Feb"))
con += "02-";
else if(mo.equals("Mar"))
con += "03-";
else if(mo.equals("Apr"))
con += "04-";
else if(mo.equals("May"))
con += "05-";
else if(mo.equals("Jun"))
con += "06-";
else if(mo.equals("Jul"))
con += "07-";
else if(mo.equals("Aug"))
con += "08-";
else if(mo.equals("Sep"))
con += "09-";
else if(mo.equals("Oct"))
con += "10-";
else if(mo.equals("Nov"))
con += "11-";
else if(mo.equals("Dec"))
con += "12-";
con += conArr[2];
con += "@BREAK";
con += con.substring(0,con.indexOf("@BREAK"));
VideoDate sel = new VideoDate(con);
serverPHPresponse = phpMain.sendPOSTReadRequest(sel);
hotStatus.setText("Query successful!");
hotStatus.setForeground(Color.GREEN);
//System.out.println(serverPHPresponse[0].printPretty());
if(serverPHPresponse[0].blank) {
hotStatus.setText("No video requests were found for the selected day.");
hotStatus.setForeground(Color.BLACK);
}
else {
reportWind pop = new reportWind(serverPHPresponse);
pop.toString();
}
}
}
And it's triggered by this in another class:
seeSched.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SchedWind main = new SchedWind();
main.toString();
}
});
The thing is, if I try and get it to open an extremely simple JFrame with nothing in it, it works. Can anyone help?
Thanks!