I've been trying to figure out this code for several days on using menus within an applet Jpanel. In my searching I've found no examples of combined use. In the following code if you switch the order in what gets added first thats all you see. If you add form information first the menubar doesn't show and the same for the reverse order.
Are these incompatible or what am I missing here. I've chopped down the code size to make things fit easier here.
TIA
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class myIcon extends JApplet
{
private void createGUI() {
JMenuBar menubar;
JMenu mnuPopup_421;
JMenuItem mnuPopupMonth_423;
JMenuItem mnuPopupMonth_427;
JMenuItem mnuPopupMonth_431;
JPanel con;
ButtonGroup cbg;
JList picCalendar_15;
JList picDays_30;
JButton cmdChangeDate_46;
JButton cmdChangeDate_58;
JButton cmdChangeDate_70;
JButton cmdChangeDate_84;
JButton cmdToday_96;
JCheckBox chkStayOnTop_105;
JButton cmdToday_113;
JButton cmdChangeDate_122;
JButton cmdChangeDate_134;
JButton cmdChangeDate_148;
JButton cmdChangeDate_160;
JButton cmdClose_172;
JList picDays_181;
JList picCalendar_197;
con = new JPanel(new BorderLayout());
con.setOpaque(true);
con.setFont(new Font("Helvetica", Font.PLAIN, 12));
con.setLayout(null);
con.setSize(526, 322);
cbg = new ButtonGroup();
//create the menubar
menubar = new JMenuBar();
// Menu Parent mnuPopup
//setting up Menu - mnuPopup_421
mnuPopup_421 = new JMenu("Month");
//setting up MenuItem - mnuPopupMonth_423
mnuPopupMonth_423 = new JMenuItem("January");
mnuPopup_421.add(mnuPopupMonth_423);
//setting up MenuItem - mnuPopupMonth_427
mnuPopupMonth_427 = new JMenuItem("February");
mnuPopup_421.add(mnuPopupMonth_427);
//setting up MenuItem - mnuPopupMonth_431
mnuPopupMonth_431 = new JMenuItem("March");
mnuPopup_421.add(mnuPopupMonth_431);
// Setting up Applet - appname
//setting up PictureBox - picDays_30
picDays_30 = new JList();
JScrollPane sppicDays_30 = new JScrollPane(picDays_30);
sppicDays_30.setLocation(280, 80);
sppicDays_30.setSize(224, 16);
con.add(sppicDays_30);
//setting up JButton - cmdToday_96
cmdToday_96 = new JButton("Today");
cmdToday_96.setBounds(280, 250, 66, 21);
con.add(cmdToday_96);
//setting up JCheckBox - chkStayOnTop_105
chkStayOnTop_105 = new JCheckBox("Stay on top of other windows.");
chkStayOnTop_105.setBounds(20, 290, 246, 18);
con.add(chkStayOnTop_105);
//setting up JButton - cmdClose_172
cmdClose_172 = new JButton("&Close");
cmdClose_172.setBounds(415, 290, 97, 25);
con.add(cmdClose_172);
//setting up PictureBox - picDays_181
picDays_181 = new JList();
JScrollPane sppicDays_181 = new JScrollPane(picDays_181);
sppicDays_181.setLocation(25, 80);
sppicDays_181.setSize(224, 16);
con.add(sppicDays_181);
//setting up PictureBox - picCalendar_197
picCalendar_197 = new JList();
JScrollPane sppicCalendar_197 = new JScrollPane(picCalendar_197);
sppicCalendar_197.setLocation(25, 105);
sppicCalendar_197.setSize(225, 138);
con.add(sppicCalendar_197);
menubar.add(mnuPopup_421);
getContentPane().add(con);
getContentPane().add(menubar);
}
public void init()
{
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
}
public static void main(String args[])
{
myIcon applet = new myIcon();
Frame window = new Frame("myIcon");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.add("Center", applet);
window.setTitle("ICD Calendar");
window.pack();
window.setVisible(true);
}
}
Are these incompatible or what am I missing here. I've chopped down the code size to make things fit easier here.
TIA
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class myIcon extends JApplet
{
private void createGUI() {
JMenuBar menubar;
JMenu mnuPopup_421;
JMenuItem mnuPopupMonth_423;
JMenuItem mnuPopupMonth_427;
JMenuItem mnuPopupMonth_431;
JPanel con;
ButtonGroup cbg;
JList picCalendar_15;
JList picDays_30;
JButton cmdChangeDate_46;
JButton cmdChangeDate_58;
JButton cmdChangeDate_70;
JButton cmdChangeDate_84;
JButton cmdToday_96;
JCheckBox chkStayOnTop_105;
JButton cmdToday_113;
JButton cmdChangeDate_122;
JButton cmdChangeDate_134;
JButton cmdChangeDate_148;
JButton cmdChangeDate_160;
JButton cmdClose_172;
JList picDays_181;
JList picCalendar_197;
con = new JPanel(new BorderLayout());
con.setOpaque(true);
con.setFont(new Font("Helvetica", Font.PLAIN, 12));
con.setLayout(null);
con.setSize(526, 322);
cbg = new ButtonGroup();
//create the menubar
menubar = new JMenuBar();
// Menu Parent mnuPopup
//setting up Menu - mnuPopup_421
mnuPopup_421 = new JMenu("Month");
//setting up MenuItem - mnuPopupMonth_423
mnuPopupMonth_423 = new JMenuItem("January");
mnuPopup_421.add(mnuPopupMonth_423);
//setting up MenuItem - mnuPopupMonth_427
mnuPopupMonth_427 = new JMenuItem("February");
mnuPopup_421.add(mnuPopupMonth_427);
//setting up MenuItem - mnuPopupMonth_431
mnuPopupMonth_431 = new JMenuItem("March");
mnuPopup_421.add(mnuPopupMonth_431);
// Setting up Applet - appname
//setting up PictureBox - picDays_30
picDays_30 = new JList();
JScrollPane sppicDays_30 = new JScrollPane(picDays_30);
sppicDays_30.setLocation(280, 80);
sppicDays_30.setSize(224, 16);
con.add(sppicDays_30);
//setting up JButton - cmdToday_96
cmdToday_96 = new JButton("Today");
cmdToday_96.setBounds(280, 250, 66, 21);
con.add(cmdToday_96);
//setting up JCheckBox - chkStayOnTop_105
chkStayOnTop_105 = new JCheckBox("Stay on top of other windows.");
chkStayOnTop_105.setBounds(20, 290, 246, 18);
con.add(chkStayOnTop_105);
//setting up JButton - cmdClose_172
cmdClose_172 = new JButton("&Close");
cmdClose_172.setBounds(415, 290, 97, 25);
con.add(cmdClose_172);
//setting up PictureBox - picDays_181
picDays_181 = new JList();
JScrollPane sppicDays_181 = new JScrollPane(picDays_181);
sppicDays_181.setLocation(25, 80);
sppicDays_181.setSize(224, 16);
con.add(sppicDays_181);
//setting up PictureBox - picCalendar_197
picCalendar_197 = new JList();
JScrollPane sppicCalendar_197 = new JScrollPane(picCalendar_197);
sppicCalendar_197.setLocation(25, 105);
sppicCalendar_197.setSize(225, 138);
con.add(sppicCalendar_197);
menubar.add(mnuPopup_421);
getContentPane().add(con);
getContentPane().add(menubar);
}
public void init()
{
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
}
public static void main(String args[])
{
myIcon applet = new myIcon();
Frame window = new Frame("myIcon");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.add("Center", applet);
window.setTitle("ICD Calendar");
window.pack();
window.setVisible(true);
}
}