IllegalArgumentException: adding window to contentPane

That's the exception I get on running this, but itdoesn't kill the program. Also, the switchColor() function changes the Box color to red the first time, but does not toggle. I've spent way longer on this then I'm proud to say.
Please help.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WindowButton1
public static void main(String[] args)
     window = new MainWindow("Action example");
     Toolkit theKit = window.getToolkit();          
     Dimension wndSize = theKit.getScreenSize();  
     window.setBounds(0, 0,wndSize.width/2, wndSize.height/2);
     window.addWindowListener(new WindowAdapter()     
          // Handler for window closing event
          public void windowClosing(WindowEvent e)
               window.dispose();                          
               System.exit(0);                            
          window.setVisible(true); // Display the window
     static MainWindow window;          
}//end WindowButton1
class MainWindow extends JFrame
     MainWindow(String title)
     super(title);
     setJMenuBar(menuBar);                  
     fileMenu = new JMenu("File");
     connectItem = new JMenuItem();                                        
     connectItem = fileMenu.add("Connect...");
     connectItem.addActionListener(menuHandler = new Handler());
     menuBar.add(fileMenu);           
}//end constructor
//innerclass to handle "Connect" menu action
class Handler implements ActionListener
     public void actionPerformed(ActionEvent e)
      win = new ConnectWindow("ColorButton Test");
      getContentPane().add(win,BorderLayout.CENTER);
      setVisible(true);
}//end inner class
private JMenu fileMenu;
private JMenuItem connectItem;
private JMenuBar menuBar = new JMenuBar(); 
private Handler menuHandler;
private ConnectWindow win;
//separate class to display buttonBox
class ConnectWindow extends JFrame
ConnectWindow(String title)
     setTitle("Action Buttons");
     Toolkit kit = Toolkit.getDefaultToolkit();
     Dimension screenSize = kit.getScreenSize();
     int screenHeight = screenSize.height;
     int screenWidth = screenSize.width;
     setSize(screenWidth / 3, screenHeight / 3);
     setLocation(screenWidth / 4, screenHeight / 4);
//buttons to go into panel
     JButton button1 = new JButton("Color Change");
     JButton button2 = new JButton("Cancel");
     JButton button3 = new JButton("Advanced");
     Dimension buttonSize = new Dimension(100,20);
     button1.setPreferredSize(buttonSize);
     button2.setPreferredSize(buttonSize);
     button3.setPreferredSize(buttonSize);
//Event handling for the three buttons
     button1.addActionListener(new ActionListener()
     public void actionPerformed(ActionEvent e)
     switchColor();
     repaint();
//Cancel button closes window
     button2.addActionListener(new ActionListener()
     public void actionPerformed(ActionEvent e)
     dispose();                            
//Advanced button is dummy for now
     button3.addActionListener(new ActionListener()
     public void actionPerformed(ActionEvent e)
//place buttons in panel
     Box buttonBox = Box.createVerticalBox();
     buttonBox.add(button1);
     buttonBox.add(button2);
     buttonBox.add(button3);
     //place button box in main window
     getContentPane().add(buttonBox, BorderLayout.CENTER);
     setVisible(true);
     }//end constructor
     public void switchColor()
          isRed = false;
          if (!(isRed))
          getContentPane().setBackground(Color.red);
          else getContentPane().setBackground(Color.white);
          setVisible(true);
          repaint();
          isRed = !(isRed);
     boolean isRed;
     private Box buttonBox;
     private JButton button1, button2, button3;
}//end ConnectWindow

Change ConnectWindow to
class ConnectWindow extends JInternalFrameHope this helps youThanks! The last piece is toggling the colors. Here's my actionPerformed method, and the method it calls (taken from the above code:
button1.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
switchColor();
repaint();
public void switchColor()
isRed = false;
if (!(isRed))
WindowButton1.window.getContentPane().setBackground(Color.red);
else getContentPane().setBackground(Color.white);
setVisible(true);
repaint();
isRed = !(isRed);
boolean isRed;

Similar Messages

  • Simple how-to guide to adding windows 7 64-bit to mavericks as a virtual machine (Virtual Box)

    Simple how-to guide to adding windows 7 64-bit to mavericks as a virtual machine (Virtual Box)
    Why use a Virtual Machine: Sometimes you need to run a windows only program.  A VM lets you do that without rebooting your machine. 
    How is it different from Mac Boot Camp: Boot camp allows you to run windows but you must reboot your machine. It is faster and smoother than a VM (and with fullscreen details below), but you have to reboot for each use. 
    Is it possible to have a VM and Boot Camp: Yes, and I do this because sometimes I want to use a VM quickly without shutting down, sometimes I want the advantages of Boot Camp
    How do I get Windows in Boot Camp: how-to here:
    https://discussions.apple.com/thread/6025059
    *Please note I accept no responsibility for issues occurring from the use of this guide, please use at your risk
    **Please note I do not propose or support using illegal copies of Windows software or licenses
    Required technical skill: minimal
    Required time: approx 30 minutes
    Required items: Mac
    Get a version of Windows 7 64-bit:
    http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_install/canno t-find-digital-river-download-site/66a8439b-0d16-4b70-92f7-1c8486a46ebf
    Windows 7 Downloads are still available.
    Download the appropriate Windows 7 .ISO file which includes Service Pack 1 
(Note: must match what your product key version is for)
    Windows 7 Home Premium 32Bit: http://msft.digitalrivercontent.net/win/X17-58996.iso Windows 7 Home Premium 64Bit: http://msft.digitalrivercontent.net/win/X17-58997.iso
    Windows 7 Professional 32Bit: http://msft.digitalrivercontent.net/win/X17-59183.iso Windows 7 Professional 64Bit: http://msft.digitalrivercontent.net/win/X17-59186.iso
    Windows 7 Ultimate 32Bit: http://msft.digitalrivercontent.net/win/X17-59463.iso Windows 7 Ultimate 64Bit: http://msft.digitalrivercontent.net/win/X17-59465.iso
    Locate your image (iso) file, example: /Users/Christoper/Downloads/X17-58997.iso.download/X17-58997.iso
    Download Virtual Box Virtual Machine Player:
    https://www.virtualbox.org/wiki/Downloads
    Install Win 7 OS:
    Open Virtual Box
    Choose “New” (Note: Once you click new it will require you to complete the process of creation, no option for quit.  If you make a mistake or are not ready, just finish it and then remove it and delete all files)
    Name: “Windows 7 Virtual” or as you choose
    Type: Microsoft Windows
    Version: Windows 7 64-bit
    Memory: I suggest 1GB if you have 4GB available, 512 MB may run slowly.  2GB+ of 4GB may slowdown your MAC OS running while the VM is running. 
    “Create a Virtual Drive Now” option
    File Size: 25 GB should be the minimum selected, I used 25GB because I expect to use the drive to store very little. 
    HD type: VirtualBox Disk Image
    Storage: Dynamically Allocated
    Locate your new VM and click Start (again you will not be able to quit once you start, if you make a mistake continue until the red quit icon appears then remove the VM)
    It will ask you to select the files for the OS.  Select the ISO file, for example: /Users/Christoper/Downloads/X17-58997.iso.download/X17-58997.iso
    Proceed to setup Win with your preferences
    Type product key from your OS purchase or an existing one that you are moving from another machine
    Note: Screen resolution may be very limited on the virtual machine.  I use resolution 800 X 600 so that all of the desktop is visible. 
    I suggest using a windows gadget to view the CPU and Memory usage > On desktop mac-right-click i.e. separate fingers and click both > Gadgets > CPU Meter
    Enjoy having Windows on your Mac!

    I have found a solution to the screen being smaller in the windows 7 virtual machine.  First right-click in the desktop region and select screen resolution.  It is probably set to 800 X 600 by default which is much less than the screensize you are using.  To determine your native screensize, go to your mac and finder > applications > utilities > hardware > graphics displays.  Mine is 1440 X 900 for macbook air.  Then go back into the virtual machine and sceen resolution settings.  Choose a screen resolution which is slightly less in all dimensions so that there is no clipping and you do not have to scroll when viewing.  For me this was 1152 X 864.  Then exit saving changes and with the VM in view press command - F (or at the menu bar View > Switch to full screen), which puts you in full screen mode.  Now you should have a screen with minimal gray empty space filling the majority of your screen

  • Simple how-to guide to adding windows 7 64-bit to mavericks with boot camp

    Simple how-to guide to adding windows 7 64-bit to mavericks with boot camp
    *Please note I accept no responsibility for issues occurring from the use of this guide, please use at your risk
    **Please note I do not propose or support using illegal copies of Windows software or licenses
    Required technical skill: minimal
    Required time: approx 1-2 hours
    Required items: Mac, USB drive or DVD-R
    Get a version of Windows 7 64-bit:
    http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_install/canno t-find-digital-river-download-site/66a8439b-0d16-4b70-92f7-1c8486a46ebf
    Windows 7 Downloads are still available.
    Download the appropriate Windows 7 .ISO file which includes Service Pack 1
    (Note: must match what your product key version is for)
    Windows 7 Home Premium 32Bit: http://msft.digitalrivercontent.net/win/X17-58996.iso
    Windows 7 Home Premium 64Bit: http://msft.digitalrivercontent.net/win/X17-58997.iso
    Windows 7 Professional 32Bit: http://msft.digitalrivercontent.net/win/X17-59183.iso
    Windows 7 Professional 64Bit: http://msft.digitalrivercontent.net/win/X17-59186.iso
    Windows 7 Ultimate 32Bit: http://msft.digitalrivercontent.net/win/X17-59463.iso
    Windows 7 Ultimate 64Bit: http://msft.digitalrivercontent.net/win/X17-59465.iso
    Burn this image file (.iso) to a USB drive or DVD-R:
    USB drive:
    Get a blank USB drive with 8 GB+ capacity
    Format this drive to Fat32 (Windows and Mac shared format), this will erase the drive!:
    Finder > Applications > Utitilies > Disk Utility > Partition > 1 > Fat32
    Extract the image file to the drive exposing its files:
    Finder > Applications > Utilites > Boot Camp Assistant
    Click both "Create a Win 7 or later version install disk" and "Download the latest windows support software from Apple" and advance
    Locate your image (iso) file, example: /Users/Christoper/Downloads/X17-58997.iso.download/X17-58997.iso
    Destination disk is your USB flash drive that was formatted to fat32, if it does not appear it may be in the wrong format
    Click continue, this process takes a long time (30 mins - 1.5 hour estimated), it may appear that it is freezing because progress bar stops at times, do not stop it, let it keep running.  If you are unsure it is still going, open finder > click the drive > get info, and look at the size of the files.  Then close finder wait a few seconds, get info again and see that file size is slightly larger.  The final file size was 4+ GB for me
    or DVD-R:
    I have not used a DVD-R but this is how I expect it to work:
    Insert black DVD-R
    Finder > Applications > Utitilies > Disk Utility > Burn
    Locate your image (iso) file, example: /Users/Christoper/Downloads/X17-58997.iso.download/X17-58997.iso
    Partition HD for WIndows 7:
    Finder > Applications > Utilites > Boot Camp Assistant
    Choose the 3rd option Install Windows 7
    It will ask you to select a size of your Harddrive space for Windows OS, this will eat up some of the free space on your Mac HD.  How much space is enough for a Windows OS?  Depends on how many programs you plan to install on it.  If you are just using for surfing web and running MS Office, probably 30-40 GB is enough, and this is what I did.  Remember this space will be used up from your existing HD and not usable when you are in Mac OS.  This process takes about 10 mins I think
    Install Win 7 OS:
    With USB drive in port or DVD in drive, restart laptop. 
    It will bring up the Win 7 installer on boot up
    Select the OS type that you have a registered key for
    It will ask you to find a HD to use for Win 7 OS:
    Select the HD you just created, if you try to continue it will complain that HD is wrong format (because MAC formatted it to a MAC compatible HD, we will fix this)
    Select the HD, there is a button to the right for "advanced" I believe is the text of it.  It will allow you to reformat the drive, choose NTFS which it requires.  Then proceed
    Proceed to setup Win with your preferences
    Type product key from your OS purchase or an existing one that you are moving from another machine
    Select Default Boot Drive:
    By default it selects Windows as your default OS to boot at power up, most people want Mac OSX to be the default, so this can be changed:
    Finder > System Preferences > Startup Disk > select Mac
    Enjoy having Windows on your Mac!

    Why use Boot Camp: Sometimes you need to run a windows only program.  Boot Camp lets you do that with the speed and smoothness of a full windows OS. 
    How is it different from Mac Virtual Machine: A VM allows you to run another OS simultaneously while you are running OSX, while in a window similar to any other application.  A VM is not as fast, smooth, and may have limited screensize/view.   
    Is it possible to have a VM and Boot Camp: Yes, and I do this because sometimes I want to use a VM quickly without shutting down, sometimes I want the advantages of Boot Camp
    How do I get Windows in VM: how-to here:
    https://discussions.apple.com/thread/6043251

  • Most secure method of adding windows for my limited purposes?

    I only need windows on this particular computer, a Macbook 13 inch 2.1 Ghz with 2 GB RAM ("111.47 GB hard disk space capacity") to run Internet Explorer in those instances where my Mac browsers (Safari, Firefox, Opera thus far) will not work on some part of a website (for instance, try ordering something on equifax.com - a major site that's not fully mac compatible). I have the latest update of Leopard. I bought the computer in the past three weeks and have run software update regularly.
    I did not want to put windows on this computer when I originally bought it. Now it appears from the failure of Mac browsers to work in some situations, I have to put windows on. I'm not even sure I can find XP although I had it on my old HP desktop I'm getting rid of. I might be forced to buy Vista and I don't have probably enough space for it to run well, do I? Do I need to upgrade to 4 gb RAM? Expensive.
    Anyway, for security purposes, I want to be very cautious in how I use windows. I found keyloggers and periodically had files show up on my old windows computer in AVG, Ad-Aware, Spybot and other programs that worried me (most recently "Omniquad" kept showing up even after I deleted it and AVG free has no notes on what this means).
    Is the least vulnerable way as far as internet viruses to run windows on my Mac to just install it in BootCamp assistant and reboot when I need it? Or theoretically is there any more vulnerability if I use VMware Fusion or Parallels with it? Do I first set it up in Bootcamp assistant (what partition size?) before I worry about choosing Vmware Fusion or Parallels? Or do I need to install one of those before I install windows?
    What was it someone was saying in a different thread about needing to edit one's "virtual machine" -- see below:
    +"One other tip, I would recommend editing the virtual machine before activation of windows to use emulate the same MAC address for your virtual ethernet card in parallels as for your real network card. This seems to convince WIN XP at lease that it is the same machine whether you boot it through boot camp or through Parallels. Otherwise, activation quickly becomes a pain."+
    (Where would my virtual machine be?)
    And also, do I need to do some special reconfiguration with my router manufacturer (Linksys) after adding windows through bootcamp and/or Parallels/Vmware in order for the the windows side to connect to the internet as my Mac is doing?
    Also: should I get Windows XP Professional or Vista in this situation with the small Macbook and limited needs? I hope XP will still be used years from now.
    P.S. I wish it weren't so hard to find out how to do all this. It makes me not want to go through this again with another computer and I actually need another.

    VMWare Fusion and Parallels create Virtual Machines. When you are running Windows inside the Mac os
    you are running a Windows Virtual Machine. A Virtual Machine accesses the physical machine differently than a Boot Camp installation, since it is going through Fusion or Parallels, which is why set-up is trickier. See this wiki article: http://en.wikipedia.org/wiki/Virtual_machine
    XP Pro was originally aimed at businesses and power users. It can access 2 physical processors (in contrast to two cores on one processor), so it benchmarks faster on my Mac Pro which has 2 dual core processors. It also has some advanced networking features. I use both XP and XP Pro at home and don't notice much difference in day to day use. You did buy the superior version of XP, and since it is aimed at businesses, Microsoft will continue to provide security updates for it long after they stop providing them for XP. So you will get some value from buying it.
    Its great that you are checking the AV Comparative site for yourself and not just relying on my opinion. The version of Avira they are using in the tests however is the Premium version, not the free version. If you notice on the AV Comparatives site, there are 2 types of tests, on demand and proactive. One reason I prefer paid versions of anti-virus software is that only they provide proactive protection. On demand protection relies on signature files that the AV company provides your copy of the program - when you update an AV program you are updating the signature files. Signature files allow the program to recognize any known virus. They will not catch something new - this is why when a new virus arrives it spreads so quickly - no one has a signature file for it so their AV program doesn't recognize it as a threat. Then your AV program gets a signature file update and you can scan and find the virus. Proactive protection works differently. It looks for certain features in a file that are common to virus files. If the file fits this profile, the program will block it even though it doesn't have a signature file for that particular virus yet. So while everyone else gets the virus maybe you don't (if you notice, the success rate for proactive protection is much lower than on demand). Yet some programs, like NOD32 and (usually) Kaspersky do proactive much better than other programs (don't know why Kaspersky slipped so much this time). I prefer NOD32 because it not only rates advanced plus in both on demand and proactive but also update signature files very quickly, uses few system resources so it doesn't slow you down, and works quietly behind the scenes
    (Kaspersky can bug you to death sometimes).

  • Adding "window to a container:illegal argument exception".error plz help

    Thanks to Mr.Andrew and sun for developing the following code for a
    mediaplayer which is implemented in jmf.This is working in core java. But
    when i have converted it to Applet it compiles but an error adding "window
    to a container:illegal argument exception".code is given below plz point
    me where is the error;
    import javax.media.*;
    import java.text.DecimalFormat;
    import java.awt.*;
    import java.awt.FileDialog;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class nwa extends WindowAdapter{
    frameclass frame;
    public nwa(frameclass frame){
    this.frame=frame;
    public void windowClosing (WindowEvent e)
    //User selected close from System menu.
    //Call dispose to invoke windowClosed.
    frame.dispose ();
    public void windowClosed (WindowEvent e)
    //if (player != null)
    //player.close ();
    System.exit (0);
    class frameclass extends JFrame
    frameclass(){
    nwa n=new nwa(this);
    this.addWindowListener(n);                    
    public class PlayerApplet extends JApplet
              implements
    ActionListener,ControllerListener,ItemListener, KeyListener
    frameclass frame=new frameclass();
    Player player;
    Component vc, cc;
    JProgressBar volumeBar;
         JButton fastRewind;
         JButton fastForward;
         JButton play;
    int sizeIncrease = 2;
    boolean invokedStop = false;
         /** Big */
         int progressFontSize=30;
    boolean first = true, loop = false;
    String currentDirectory;
    public void init(){
    JMenu m = new JMenu ("File");
    JMenuItem mi = new JMenuItem ("Open...");
    mi.addActionListener (this);
    m.add (mi);
    m.addSeparator ();
    JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem ("Loop", false);
    cbmi.addItemListener (this);
    m.add (cbmi);
    m.addSeparator ();
    mi = new JMenuItem ("Exit");
    mi.addActionListener (this);
    m.add (mi);
    JMenuBar mb = new JMenuBar ();
    mb.add (m);
    frame.setJMenuBar (mb);
    setSize (200, 200);
         final JPanel p = new JPanel(new GridLayout(1,0,5,5));
              p.setBorder(new EmptyBorder(3,5,5,5) );
              fastRewind = new JButton("<html><body><font size=+"+
    sizeIncrease+ "><<");
              fastRewind.setToolTipText("Fast Rewind");
              fastRewind.addActionListener( new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        if (player!=null) {
                             invokedStop = false;
                             skipBack();
                        } else {
    JOptionPane.showMessageDialog(play,
                             new JLabel("Open a sound file
    first!"));
              fastRewind.addKeyListener(this);
              p.add(fastRewind);
              JButton stop = new JButton("<html><body><font size=+"+
    sizeIncrease+ ">&#9632;");
              stop.setToolTipText("Stop");
              stop.addActionListener( new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        invokedStop = true;
                        //player.stop();
                        sp();
              stop.addKeyListener(this);
              p.add(stop);
              play = new JButton("<html><body><font size=+"+
    sizeIncrease+ ">>");
              play.setToolTipText("Play");
              play.addActionListener( new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        if (player!=null) {
                             invokedStop = false;
                             player.setRate(1);
                             st();
                        } else {
    JOptionPane.showMessageDialog(play,
                             new JLabel("Open a sound file
    first!"));
              play.addKeyListener(this);
              p.add(play);
              fastForward = new JButton("<html><body><font size=+"+
    sizeIncrease+ ">>>");
              fastForward.setToolTipText("Fast Forward");
              fastForward.addActionListener( new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        if (player!=null) {
                             invokedStop = false;
                             skipForward();
                        } else {
    JOptionPane.showMessageDialog(play,
                             new JLabel("Open a sound file
    first!"));
              fastForward.addKeyListener(this);
              p.add(fastForward);
              p.addKeyListener(this);
              frame.add(p,BorderLayout.CENTER);     
              add(frame);
    // pack ();
    setVisible (true);
    public void start(){
    st();
    public void stop(){
    sp();
    public void destroy(){
    player.stop();
    player.deallocate();
    public void actionPerformed (ActionEvent e)
                   if (e.getActionCommand().equals("Exit"))
                   // Call dispose to invoke windowClosed.
                   frame.dispose ();
                        return;
         FileDialog fd = new FileDialog (frame, "Open File",
    FileDialog.LOAD);
         fd.setDirectory (currentDirectory);
         fd.show ();
         // If user cancelled, exit.
              if (fd.getFile() == null)
         return;
    currentDirectory = fd.getDirectory ();
              if (player != null)
         player.close ();
         try
         player = Manager.createPlayer (new MediaLocator
    ("file:" +
    fd.getDirectory() +
    fd.getFile()));
         catch (java.io.IOException e2)
    System.out.println (e2);
    return;
         catch (NoPlayerException e2)
    System.out.println ("Could not find a player.");
    return;
              if (player == null)
         System.out.println ("Trouble creating a player.");
         return;
    first = false;
    frame.setTitle (fd.getFile ().toString());
    player.addControllerListener (this);
    player.prefetch ();
    public void controllerUpdate (ControllerEvent e)
    if (e instanceof ControllerClosedEvent)
    if (vc != null)
    remove (vc);
    vc = null;
    if (cc != null)
    remove (cc);
    cc = null;
    return;
    if (e instanceof EndOfMediaEvent)
    if (loop)
    player.setMediaTime (new Time (0));
    player.start ();
    return;
    if (e instanceof PrefetchCompleteEvent)
    player.start ();
    return;
    if (e instanceof RealizeCompleteEvent)
    vc = player.getVisualComponent ();
    if (vc != null)
    add (vc);
    cc = player.getControlPanelComponent ();
    if (cc != null){
         this.add (cc, BorderLayout.SOUTH);
                        this.show();
    public void keyReleased(KeyEvent ke) {
    int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
         public void keyTyped(KeyEvent ke) {
         int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
         public void keyPressed(KeyEvent ke) {
              int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
              }else if (keycode==KeyEvent.VK_UP) {
                   st();
              }else if (keycode==KeyEvent.VK_DOWN) {
                   sp();
    public void skipForward() {
    double secs=5;
    double playersecs = player.getMediaTime().getSeconds();
    Time settime = new javax.media.Time(playersecs + secs);
    player.setMediaTime(settime);
    public void skipBack() {
              double secs1=5;
    double playersecs1 = player.getMediaTime().getSeconds();
    Time settime1 = new javax.media.Time(playersecs1 - secs1);
    player.setMediaTime(settime1);
         public void st() {
         player.start();
         public void sp() {
         player.stop();
    public void itemStateChanged (ItemEvent e)
    loop = !loop;
    When i comment add(frame) this error goes but i got a null poiter
    exception
    Plz help
    manu

    Hi Andrew,
    Thanks for ur reply.Sorrry that my code not included in the code block.
    My problem have been solved partly.Now playerapplet is working properly.It can play files from local machine(through open menuitem from file menu) as well as local network (through url menuitem from file menu).
    There is no requirement to play file from internet at present.
    I have given arrow keys to forward/backward/open/close.
    I have now completed my first part of project.Now i have to start the second part ie Controlling arrow keys using a joystick like instrument.The instrument and driver will be provided by my co. and the user is using only this device.Plz help me how to do that.
    The code is given below
    import javax.media.*;
    import java.text.DecimalFormat;
    import java.awt.*;
    import java.awt.FileDialog;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    <APPLET CODE=PlayerApplet.class
    WIDTH=320 HEIGHT=300>
    </APPLET>
    class nwa extends WindowAdapter
         frameclass frame;
         Player player;
         public nwa(frameclass frame,Player player)
          this.player=player;
          this.frame=frame;
         public void windowClosing (WindowEvent e)
          //User selected close from System menu.
          //Call dispose to invoke windowClosed.
          frame.dispose ();
          public void windowClosed (WindowEvent e)
              if (player != null)
                   player.stop();
                player.close ();
                   player.deallocate();
          System.exit (0);
    class frameclass extends JFrame
    Player player;
         frameclass(Player player)
         nwa n=new nwa(this,player);
         this.addWindowListener(n);                    
    public class PlayerApplet extends JApplet
               implements ActionListener,ControllerListener,ItemListener, KeyListener
               Player player=null;
               frameclass frame=new frameclass(player);
                 Component vc, cc;
                 Container f;
                 JProgressBar volumeBar;
                 JButton fastRewind;
              JButton fastForward;
              JButton play;
              int sizeIncrease = 2;
              boolean invokedStop = false;
              /** Big */
              int progressFontSize=30;
                 boolean first = true, loop = false;
                 String currentDirectory;
                 public void init()
                          f=frame.getContentPane();
                         JMenu m = new JMenu ("File");
                         JMenuItem mi = new JMenuItem ("Open...");
                         mi.addActionListener (this);
                         m.add (mi);
                         m.addSeparator ();
                         mi = new JMenuItem ("URL");
                         mi.addActionListener (this);
                         m.add (mi);
                         m.addSeparator ();
                         JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem ("Loop", false);
                         cbmi.addItemListener (this);
                         m.add (cbmi);
                         m.addSeparator ();
                         mi = new JMenuItem ("Exit");
                         mi.addActionListener (this);
                         m.add (mi);
                         JMenuBar mb = new JMenuBar ();
                         mb.add (m);
                         frame.setJMenuBar (mb);
                         setSize (500, 500);
                           JPanel p = new JPanel(new GridLayout(1,0,5,5));
                        p.setBorder(new EmptyBorder(3,5,5,5) );
                        fastRewind = new JButton("<html><body><font size=+"+ sizeIncrease+ "><<");
                        fastRewind.setToolTipText("Fast Rewind");
                        fastRewind.addActionListener( new ActionListener(){
                             public void actionPerformed(ActionEvent ae) {
                                  if (player!=null) {
                                       invokedStop = false;
                                       skipBack();
                                  } else {
                                       JOptionPane.showMessageDialog(play,
                                       new JLabel("Open a sound file first!"));
                        fastRewind.addKeyListener(this);
                        p.add(fastRewind);
                        JButton stop = new JButton("<html><body><font size=+"+ sizeIncrease+ ">&#9632;");
                        stop.setToolTipText("Stop");
                        stop.addActionListener( new ActionListener(){
                                  public void actionPerformed(ActionEvent ae) {
                                       invokedStop = true;
                                       sp();
                        stop.addKeyListener(this);
                        p.add(stop);
                        play = new JButton("<html><body><font size=+"+ sizeIncrease+ ">>");
                        play.setToolTipText("Play");
                        play.addActionListener( new ActionListener()
                                  public void actionPerformed(ActionEvent ae) {
                                       if (player!=null) {
                                            invokedStop = false;
                                            player.setRate(1);
                                            st();
                                       } else {
                                            JOptionPane.showMessageDialog(play,
                                            new JLabel("Open a sound file first!"));
              play.addKeyListener(this);
              p.add(play);
              fastForward = new JButton("<html><body><font size=+"+ sizeIncrease+ ">>>");
              fastForward.setToolTipText("Fast Forward");
              fastForward.addActionListener( new ActionListener(){
                   public void actionPerformed(ActionEvent ae) {
                        if (player!=null) {
                             invokedStop = false;
                             skipForward();
                        } else {
                             JOptionPane.showMessageDialog(play,
                             new JLabel("Open a sound file first!"));
              fastForward.addKeyListener(this);
              p.add(fastForward);
              frame.getContentPane().add(p,BorderLayout.CENTER);
              frame.setVisible (true);
              frame.pack();
              frame.setResizable(false);
      public void stop(){
      sp();
      public void destroy(){
       player.stop();
        player.deallocate();
      public void actionPerformed (ActionEvent e)
              if (e.getActionCommand().equals("Exit"))
                             // Call dispose to invoke windowClosed.
                             player.stop();
                             player.close();
                             player.deallocate();
                             frame.dispose ();
                                  return;
              if (e.getActionCommand().equals("Open..."))
                             FileDialog fd = new FileDialog (frame, "Open File",
                                         FileDialog.LOAD);
                              fd.setDirectory (currentDirectory);
                              fd.show ();
                              // If user cancelled, exit.
                              if (fd.getFile() == null)
                             return;
                              currentDirectory = fd.getDirectory ();
                                   if (player != null){
                                       player.close ();
                                       player.deallocate();
                         try
                  player = Manager.createPlayer (new MediaLocator
                                               ("file:" +
                                               fd.getDirectory() +
                                               fd.getFile()));
                              catch (java.io.IOException e2)
                            System.out.println ("file not found :"+e2);
                            return;
                              catch (NoPlayerException e2)
                            System.out.println ("Could not find a player.");
                            return;
                    if (player == null)
                   System.out.println ("Trouble creating a player.");
                   return;
                    first = false;
                    frame.setTitle (fd.getFile ().toString());
                    player.addControllerListener (this);
                    player.prefetch ();
                   return;
              if (e.getActionCommand().equals("URL"))
                             FileDialog fd = new FileDialog (frame, "Open File",
                                         FileDialog.LOAD);
                         fd.setDirectory (currentDirectory);
                         fd.show ();
                         // If user cancelled, exit.
                              if (fd.getFile() == null)
                             return;
                         currentDirectory = fd.getDirectory ();
                              if (player != null){
                                       player.close ();
                                       player.deallocate();
                   try
                        URL url = new URL ("file://"+fd.getDirectory()+fd.getFile());
                    MediaLocator mediaLocator = new MediaLocator (url);
                        player = Manager.createPlayer (mediaLocator);
                   catch (java.io.IOException e2)
                  System.out.println ("file not found :"+e2);
                  return;
                    catch (NoPlayerException e2)
                  System.out.println ("Could not find a player.");
                  return;
                    if (player == null)
                   System.out.println ("Trouble creating a player.");
                   return;
          first = false;
          frame.setTitle (fd.getFile ().toString());
          player.addControllerListener (this);
          player.prefetch ();
              return;
       public void controllerUpdate (ControllerEvent e)
          if (e instanceof ControllerClosedEvent)
              if (vc != null)
                  frame.getContentPane().remove (vc);
                  vc = null;
              if (cc != null)
                  frame.getContentPane().remove (cc);
                  cc = null;
              return;
          if (e instanceof EndOfMediaEvent)
              if (loop)
                  player.setMediaTime (new Time (0));
                  player.start ();
              return;
          if (e instanceof PrefetchCompleteEvent)
              player.start();
              return;
          if (e instanceof RealizeCompleteEvent)
            if (vc != null)
                  remove (vc);
                  vc = null;
              if (cc != null)
                  remove (cc);
                  cc = null;
              vc = player.getVisualComponent ();
              if (vc != null)
                  frame.getContentPane().add(vc,BorderLayout.NORTH);
              cc = player.getControlPanelComponent ();
              if (cc != null){
                       frame.getContentPane().add (cc, BorderLayout.SOUTH);
                     frame.setVisible(true);
                     frame.pack();
    public void keyReleased(KeyEvent ke) {
    int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
         public void keyTyped(KeyEvent ke) {
         int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
         public void keyPressed(KeyEvent ke) {
              int keycode = ke.getKeyCode();
              if (keycode==KeyEvent.VK_LEFT) {
                   skipBack();
              } else if (keycode==KeyEvent.VK_RIGHT) {
                   skipForward();
              }else if (keycode==KeyEvent.VK_UP) {
                   st();
              }else if (keycode==KeyEvent.VK_DOWN) {
                   sp();
    public void skipForward() {
    Time settime;
    double secs=5;
    double playersecs = player.getMediaTime().getSeconds();
    double duration = player.getDuration().getSeconds();
              if((playersecs+secs) < duration){
                      settime = new javax.media.Time(playersecs + secs);
                      player.setMediaTime(settime);
              }else {
                        player.setMediaTime(new Time(duration));
    public void skipBack() {
              double secs1=5;
              double secs2=0;
              double playersecs1 = player.getMediaTime().getSeconds();
              Time settime1;
              if((playersecs1 - secs1) > secs2){
                      settime1 = new javax.media.Time(playersecs1 - secs1);
                      player.setMediaTime(settime1);
              }else {
                        player.setMediaTime(new Time(0));
         public void st() {
         player.start();
         public void sp() {
         player.stop();
       public void itemStateChanged (ItemEvent e)
          loop = !loop;
    With Thanks
    manuEdited by: mm_mm on Nov 27, 2007 11:09 PM

  • Adding Windows server to my company Need Advice

    Hello,
    I own and operate hostoople.com. I have just added windows servers and want to keep my servers on my racks in Dallas Texas.  I dont want to spend 800-1k upfront for a license for my windows servers. Is there any one i can lease the license thru month
    to month then purchase it?  And in house financing programs?I want to expand this product line out .
    Any help would be great, thank you Nick Anderson

    This depends on what's doing the routing for your vlans. Do you have a L3 switch, or are you using subinterfaces on the router? By default, all vlans can route between all other vlans, so technically you should be able to add the server to whichever vlan you want. You didn't tell us where the clients are in relation to the server. Are they on the other side of the router? Is the server on the same side as the clients? If the clients are connected to one of the 3 switches along with the router, then you shouldn't have any problems. Make the switchport that the server connects to an access port to the vlan that you want it on. Then verify that the vlan is on the trunk port between switches.
    HTH,
    John

  • Adding to the ContentPane

    Pretty basic question I have...
    You know how when you add a component, say a JPanel, to the contentPane on the SOUTH. And then you add another component to the EAST. The south component always overrides the east component so the east component does not extend all the way to the bottom of the window. How do I make it so the east JPanel extends from the top to the bottom of the window on the right side? Then have another JPanel on the bottom that ends as soon as it contacts the east panel?
    Thanks,
    Steve

    You may want to use a different layout manger than BorderLayout. But if you have your heart stuck on a BorderLayout:
    If you have a panel that is to be added to the center already, you can put the center pane inside another panel with a BorderLayout, adding you center pane newCenterPane.add(BorderLayout.CENTER, centerPane); and the pane that you want at the bottom newCenterPane.add(BorderLayout.SOUTH, southPane); then just add your east pane to the main content pane add(BorderLayout.EAST, eastPane);
    I know it may be confusing, that is why you may want to look at using a GridBagLayout.
    Lates
    Cardwell

  • Adding Windows folders to iTunes library - 2 copies of song

    Having some trouble figuring out how to import preexisting mp3's into the iTunes library. The mp3's are ripped from my own CD collection using Windows Media Player. For discussion let's say I have 50 mp3's in a folder I created called iPod1. I go to iTunes and under the File menu click on "Add a folder to library" - no problem iTunes recognizes the folder and adds them to the library. Adding additional songs to the library is where the trouble starts. If I add songs to the the original Windows folder (as I'd prefer to) when I attempt to add the folder with the additional songs to the iTunes library - all of the songs are imported including the originals giving me doubles of the originals. Any suggestions appreciated. Rich
    Dell   Windows XP  

    Thanks - that makes sense. Ultimately the goal would be to have all of one's mp3 files in one folder in Windows and all of them in the iTunes library ... right? Right now I only have a portion of them in the library. There are a lot of them so it might be best to start all over - get them all in one folder and "Add that folder" to the library. Then any new files can be added individually (sorted by date as you suggest). I understand that I would lose current playlists etc. All above correct?? Rich
    Dell   Windows XP  

  • Adding Windows folders to iTunes library

    Having some trouble figuring out how to add preexisting mp3's into the iTunes library. The mp3's are ripped from my own CD collection using Windows Media Player. For discussion let's say I have 50 mp3's in a folder I created called iPod1. I go to iTunes and under the File menu click on "Add a folder to library" - no problem iTunes recognizes the folder and adds them to the library. Adding additional songs to the library is where the trouble starts. If I add songs to the the original Windows folder (as I'd prefer to) when I attempt to add the folder with the additional songs to the iTunes library - all of the songs are imported including the originals giving me doubles of the originals. If I choose to create a new folder - let's say iPod2 - the song titles seem to be imported but sometimes iTunes can't find the new folder and they appear in the library with an explanation point in front of them. By reimporting that folder sometimes iTunes can find the song. I prefer not to have my mp3's scattered in a bunch of folders in Windows. Seems like I'm missing something here. Suggestions appreciated. Thanks, Rich
    Dell   Windows XP  

    Thanks - that makes sense. Ultimately the goal would be to have all of one's mp3 files in one folder in Windows and all of them in the iTunes library ... right? Right now I only have a portion of them in the library. There are a lot of them so it might be best to start all over - get them all in one folder and "Add that folder" to the library. Then any new files can be added individually (sorted by date as you suggest). I understand that I would lose current playlists etc. All above correct?? Rich
    Dell   Windows XP  

  • Adding Windows Printer Tab in Snow Leopard

    Hello,
    I have a HP Deskjet F2280 connected Via USB into my Windows XP PC. I have been using this PC as a print server and have had no problems connecting to it through my macbook running leopard through SAMBA.
    Now after my upgrade to SL i am unable to connect to the printer. I have tried deleting the printer under the printer system preferences, but i am now unable to add the printer again - I installed the printer in leopard 10.5 previously through the windows tab under add printer in printer preferences.
    Now in SL the Windows tab is greyed out. I have doubled checked that my mac is part of my workgroup in the WINS tab in network preferences, and i have checked if file (SMB) and printer sharing are turned on. My firewall is also off. For some reason i cant work out why i cant add a windows printer. Does SL require a new way to register workgroups?
    Any help would be appreciated.
    P.S: I know HP drivers arent really supported in SL, but usually i could use the generic postscript driver, and this usually works under 10.5

    I don't believe you need to do anything different in SL to connect to a Windows shared printer.
    On my SL Mac, the Add Printer > Windows icon is still available and that is with both File and Printer sharing disabled on SL. I also don't a Workgroup name entered in WINS, although if you did I don't see this stopping the add Windows printer function.
    If you open Finder, do you see the Windows box in the Shared view?
    You may be able to work around the Add Printer issue by adding the Advanced menu to the Add Printer toolbar (control-click on the toolbar, select customize and drag the Advanced icon to the toolbar). If you then change the Type to Windows, you can enter the path to the printer in the URL section (smb://Windowsname/printer_sharename) and select the Generic PS in print using menu. Hopefully the Windows menu is available for you in this view...
    Pahu

  • Adding Windows 7 x64 drivers to Windows Server 2003 printserver

    Hello,
    I've recently added a HP Elitebook 8530W running Windows 7 64 bit, to a network containing only 32 bit systems.
    It's all working fine except I cannot get the printer, a HP Laserjet 4345MX, shared via a HP ML350 server running Windows Server 2003 SP2, working on it.
    I have downloaded the appropriate Windows 7 x64 drivers from the HP website (the PCL6 v5.2 package) and tried adding these on the server (through printer properties, sharing, additional drivers, under the x64 box), but it is refusing to accept these drivers (I've tried every .inf in the package).
    If anyone could offer any advice on how to get this setup working that'd be great, thanks
    Marijn

    Hello,
    I've recently added a HP Elitebook 8530W running Windows 7 64 bit, to a network containing only 32 bit systems.
    It's all working fine except I cannot get the printer, a HP Laserjet 4345MX, shared via a HP ML350 server running Windows Server 2003 SP2, working on it.
    I have downloaded the appropriate Windows 7 x64 drivers from the HP website (the PCL6 v5.2 package) and tried adding these on the server (through printer properties, sharing, additional drivers, under the x64 box), but it is refusing to accept these drivers (I've tried every .inf in the package).
    If anyone could offer any advice on how to get this setup working that'd be great, thanks
    Marijn

  • Adding Window to a Report

    I'm trying to generate a report in Designer 10g. The trigger Before Report is created by defult once the report is generated, the line:
    SRW.DO_SQL('alter session set NLS_DATE_FORMAT=''YYYY/MM/DD HH24:MI:SS'''); is found in the trigger.
    To avoid this situation one person in an Oracle Forum gave me an advice, he told me to create an Event in the Aplication Logic of the Window Module in Designer. The event that I had to create is BeforeReport and I had to put in Override the logic line of the event.
    In fact that counsel works but there are reports who doesn't have a window and I have several questions:
    1. What can I do if my report doesn't have a windows?
    2. Can I add a windows?
    3. How the adding of a windows can affect the structure and display of the
    information of my report?.
    All the actions envolve in solving this issue must be done from Designer 10g(things to correct or add). I want to avoid doing thing after generation in Developer.

    I have found the FormType for the form I want they are detailed here:
    /people/lutz.morrien3/blog/2004/10/01/all-sap-business-one-formtypes-at-one-look

  • Adding Windows AD Server to Mac OD Domain

    Help...
    We are adding an Active Directory server to our network, to assist with larger groups and email issues. Problem is, through searching I've found people who say it is easy and others who say it will just fall apart. But... Nothing concrete about how to properly go about making sure it works the way it is supposed to...
    Anyone know of any good articles or documentation about adding in a AD server? Eventually we need to promote it to the master and still have the mac servers as replicas (or at least still part of the system, so we can update them as needed).
    Any thoughts?
    At this point I have the server up and running, but it will not bind to the OD master.  It keeps complaining about the username and password being wrong (even though they are not, and I've tried many different accounts).  I tried adding the AD server as a replica of the OD master, and that failed as well.  The OD server said that the replica was missing the Server app...
    Thanks for any help with this, at all...
    --Charles...

    Received this from a community member on SpiceWorks forums...
    David_CSG  wrote:
    It won't work in the direction you're trying to go, never has and isn't even supported. Joining Windows AD to Apple's Open Directory has never been an option from Microsoft, and I would recommend strenuously (even vehemently) against trying at all (via any 3rd-party software) where a Domain Controller is involved. Just don't.
    Your best & only option is in the other direction, and is built-in and supported by the Mac OS: Binding FROM the Mac (server or client) to Active Directly.
    The best you could do is authenticate your Windows client (only !) machines to Apple's Open Directory via pGina, see http://pgina.org/
    That will not provide any AD domain administration features at all as the Apple OD server doesn't even offer them = Group Policy, and more.
    http://community.spiceworks.com/topic/563735-integrating-active-directory-into-o ur-mac-mavericks-open-directory-domain?page=1#entry-3684109

  • Question about adding Windows 2012 R2 Domain Controller, into a native Windows 2008 R2 single forest domain

    I current have a two server domain, both Windows 2008 R2 and fully updated.   The two servers are on subnet 10.0.1.0 /24
    - Windows 2008 R2 Server A: 10.0.1.1 (DC, GC, FSMO, DNS)
    - Windows 2008 R2 Server B: 10.0.1.2 (DC, GC)
    AD Domain: COMPANY.LOCAL
    I have a second connected subnet, 192.168.1.0 /24) which is routed to the 10.0.1.0/24 subnet and I would like to install a Windows 2012 R2 server onto a server on that subnet and make it a domain controller with AD-Integrated DNS and DHCP for the 192.168.1.0
    /24 subnet.
    - Windows 2012 R2 Server C: 192.168.1.1
    What are the proper progression steps, in order to bring up the Windows 2012 R2 server and then add it to my COMPANY.LOCAL domain and then promote it do a DC/GC/AD-Integrated DNS server?   Are they anything like the following:
    1. Install Windows 2012 R2 server (Server C)
    2. Point Windows 2012 R2 server DNS servers at Server's A and B
    3. Perform AD prep to extend AD schema to support Windows 2012 R2 domain controllers
    4. Promote Windows 2012 R2 server to domain controller (install local DNS service on Server C, during this step)
    * Question:  Will Windows automatically create a DNS zone for the Windows 2012 R2 subnet (192.168.1.0/24) AND also include the DNS zone from the previous Windows 2008 R2 domain (10.0.1.0 /24)?  Or will I need to add the 10.0.1.0 /24 zone to the DNS
    server on Server C, even though the DNS from the Windows 2008 R2 domain is AD integrated?

    Hi,
    Regarding the issue here, please take a look into below articles:
    System Requirements and Installation Information for Windows Server 2012 R2
    http://technet.microsoft.com/en-us/library/dn303418.aspx
    Release Notes: Important Issues in Windows Server 2012 R2
    http://technet.microsoft.com/en-us/library/dn387077.aspx
    Install a Replica Windows Server 2012 Domain Controller in an Existing Domain (Level 200)
    http://technet.microsoft.com/en-us/library/jj574134.aspx
    Here is an example for promoting Windows Server 2012 to a DC, see:
    Step-by-Step Guide for Setting Up A Windows Server 2012 Domain Controller
    http://social.technet.microsoft.com/wiki/contents/articles/12370.step-by-step-guide-for-setting-up-a-windows-server-2012-domain-controller.aspx
    As the server is promoted to a DC, DNS Zones will be replicated and synchronized to it automatically whenever the new one is added to an AD DS domain,  bascially there is no special need to add zones,  for more information, please see:
    Understanding Active Directory Domain Services Integration
    http://technet.microsoft.com/en-us/library/cc726034.aspx
    Hope this may help
    Best regards
    Michael
    If you have any feedback on our support, please click
    here.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Will bootcamp-adding windows make all normal windows programs work on my mac?

    Hi, I'm not really sure how bootcamp works...
    A few years ago I switched over to Mac and have really enjoyed using my mac, but the problem is, a lot of the video games I used to play with my little brother I cant download on my mac like I could on my old pc. if i got bootcamp, and it was the correct one and everything, would I be able to use all of these windows games/ programs that I can't use right now?
    For example, i cannot download a game call s4 league on mac because they only have a windows version. if i use bootcamp, will that mean i will be able to download it?
    Thanks sooo much!

    Boot Camp Assistant you have, it is in Utilities.
    Windows you have to buy.
    Depending in your MBP as to graphics capability but those can't be changed. Adding RAM and new hard drive in earlier models like yours probably can be upgraded. But not processor or gpu.
    Boot Camp is a partitioning tool and set of drivers. Period.

Maybe you are looking for