Results 1 to 8 of 8
  1. #1
    Manojx is offline Member
    Join Date
    Mar 2011
    Rep Power

    Exclamation Can anyone help out to meet this criteria

    hi to all i'm a beginner to java i have been trying to create something like the interface is divided into two panes on the left side buttons appear and on the right side content of the button is displays so when you click a button on the left side then the contents will be changed on the right side accordingly the button is pressed

    can anyone tell me which method i should use to meet this criteria

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    It's going to take quite a bit of GUI work. I really suggest you take a solid look at the sun swing tutorial. This task isn't very difficult but you will need to learn a bit. Look up border layout and action handling. The tutorial may have examples similar to what you are trying to do.

  3. #3
    Manojx is offline Member
    Join Date
    Mar 2011
    Rep Power

    Exclamation Can anyone tell me how to execute this or give a clear explanation about it

    here instead of using netbeans to execute all programs can't i use Command prompt for the execution of the program. i have already learned java but not so depth here this thing i already posted here and had gotten reply that JApplet was not there in the code and i further don't know what exactly to do can you tell what to do to execute the program here i got just an empty applet window no any components in it after the has been code executed.
    as well it displays this error message

    i think you may need some files came along with this i can't attach them here so by following this link you can download all the files that required to execute this program

    IN THIS LINK Take a look at " S " Section and download the "SplitPaneDemo" files.

    How to Use Split Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)



    java.lang.NoClassDefFoundError: SplitPaneDemo (wrong name: components/SplitPaneD
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass( :620)
    at sun.applet.AppletClassLoader.findClass(AppletClass
    at java.lang.ClassLoader.loadClass( 06)
    at sun.applet.AppletClassLoader.loadClass(AppletClass
    at java.lang.ClassLoader.loadClass( 51)
    at sun.applet.AppletClassLoader.loadCode(AppletClassL
    at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:778)
    at sun.applet.AppletPanel.runLoader( 707)

    here is the code
    Java Code:
    package components;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    /* <applet code = "SplitPaneDemo.class" height =200 width = 400>
    </applet> */
    //SplitPaneDemo itself is not a visible component.
    public class SplitPaneDemo extends JPanel
                              implements ListSelectionListener {
        private JLabel picture;
        private JList list;
        private JSplitPane splitPane;
        private String[] imageNames = { "Bird", "Cat", "Dog", "Rabbit", "Pig", "dukeWaveRed",
            "kathyCosmo", "lainesTongue", "left", "middle", "right", "stickerface"};
        public SplitPaneDemo() {
            //Create the list of images and put it in a scroll pane.
            list = new JList(imageNames);
            JScrollPane listScrollPane = new JScrollPane(list);
            picture = new JLabel();
            JScrollPane pictureScrollPane = new JScrollPane(picture);
            //Create a split pane with the two scroll panes in it.
            splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                       listScrollPane, pictureScrollPane);
            //Provide minimum sizes for the two components in the split pane.
            Dimension minimumSize = new Dimension(100, 50);
            //Provide a preferred size for the split pane.
            splitPane.setPreferredSize(new Dimension(400, 200));
        //Listens to the list
        public void valueChanged(ListSelectionEvent e) {
            JList list = (JList)e.getSource();
        //Renders the selected image
        protected void updateLabel (String name) {
            ImageIcon icon = createImageIcon("images/" + name + ".gif");
            if  (icon != null) {
            } else {
                picture.setText("Image not found");
        //Used by SplitPaneDemo2
        public JList getImageList() {
            return list;
        public JSplitPane getSplitPane() {
            return splitPane;
        /** Returns an ImageIcon, or null if the path was invalid. */
        protected static ImageIcon createImageIcon(String path) {
  imgURL = SplitPaneDemo.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("SplitPaneDemo");
            SplitPaneDemo splitPaneDemo = new SplitPaneDemo();
            //Display the window.
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    You never replied to my comment in your previous post, why? If you had, we may have been able to help you a while ago.

    You are trying to run the code as a JApplet but there is no code to create a JApplet, and I was asking if the code for this was elsewhere. Because if it isn't then it seems as if you're trying to create a JApplet by guessing, by not reading the tutorials on how to do this first, and this won't work. I suggest that you do this now. Start here: Applets Tutorial

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

  6. #6
    Manojx is offline Member
    Join Date
    Mar 2011
    Rep Power

    Question Can anyone tell me how to cope with this problem

    Hi thnx for giving that tutorial anyhow that applet was working but in that program it was explained to change the image on the right side when a name is selected from the left side so it was clear

    now another doubt arises

    can u have any idea for changing the contents on the right side when a appropriate button is clicked on the left side

    AND furthermore in the previous example they gave names of the images in another separate file called something image properties so that the source file loaded all the images from that image properties file

    but as per my requirements in the program i need the content to be changed when a appropriate button is clicked so do you have any suggestion to handle this

    expecting Reply

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Use a CardLayout and swap "cards" if the button is pressed. The same tutorial has a section on layouts including the CardLayout.

  8. #8
    Manojx is offline Member
    Join Date
    Mar 2011
    Rep Power


    In this following code snippet how do i set buttons display one after other here it displays in the same line as this button panel has default Flowlayout manger

    but now i want here to display buttons buttons one after another and i think to implement that i need to use GridBagLayout Manager but i don't how to set Gridbaglayout Manager to the Button panel (buttonP)
    Can you say any suggestion to implement that

    here is the code as follows

    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    <applet code="Card1.class" width=600 height=100></applet>
    /* This applet demonstrates using the CardLayout manager.
    Pressing one of three buttons will cause a different "card" to be
    public class Card1 extends Applet implements ActionListener
      Panel cardPanel;        // the container that will hold the various "cards"
      Panel firstP, secondP, thirdP;  // each of these panels will constitute the "cards"
      Panel buttonP;                  // panel to hold three buttons
      Button first, second, third;    // the three buttons
      CardLayout ourLayout;           // the card layout object
      public void init()
        //create cardPanel which is the panel that will contain the three "cards"
        cardPanel = new Panel();
        //create the CardLayout object
        ourLayout = new CardLayout();    
        //set card Panel's layout to be our Card Layout
        cardPanel.setLayout (ourLayout);
        //create three dummy panels (the "cards") to show
        firstP = new Panel();
        secondP = new Panel();
        thirdP = new Panel();
        //create three buttons and add ActionListener
        first = new Button("First");
        second = new Button("Second");
        third = new Button("Third");
        //create Panel for the buttons and add the buttons to it
        buttonP = new Panel();   // Panel's default Layout manager is FlowLayout
        //setLayout for applet to be BorderLayout
        this.setLayout(new BorderLayout());
        //button Panel goes South, card panels go Center
        this.add(buttonP, BorderLayout.WEST);
        this.add(cardPanel, BorderLayout.CENTER);
        // add the three card panels to the card panel container
        // method takes 1.) an Object (the card) 2.) an identifying String
        // first one added is the visible one when applet appears
        cardPanel.add(firstP, "First");     //blue
        cardPanel.add(secondP, "Second");   //yellow
        cardPanel.add(thirdP, "Third");     //green
      // respond to Button clicks by showing the so named Panel
      // note use of the CardLayout method show(Container, "identifying string")
      public void actionPerformed(ActionEvent e)
        if (e.getSource() == first)
, "First");
        if (e.getSource() == second)
, "Second");
        if (e.getSource() == third)
, "Third");
    } // end class

Similar Threads

  1. Meet the code please
    By Cylab in forum New To Java
    Replies: 9
    Last Post: 08-12-2010, 04:14 PM
  2. Replies: 3
    Last Post: 03-10-2010, 05:51 PM
  3. Replies: 0
    Last Post: 09-02-2009, 03:28 PM
  4. Replies: 0
    Last Post: 08-31-2009, 09:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts