Java-Video-Tutorial-25

Java Swing JList

2 Responses to “Java-Video-Tutorial-25”

  1. wilsonlee says:

    hi,i have few question to ask,why my code cant display message dialog?

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.geom.Ellipse2D;
    import java.awt.event.*;
    import java.awt.Graphics;
    import javax.swing.*;
    import java.lang.*;

    public class Shape extends JFrame {
    JMenuBar jmb;
    JMenu fileMenu,JSave,JOpen,file,jExit;
    String cm;
    JButton button =new JButton();
    Graphics g = getGraphics();
    JComboBox anyshape;

    String []newx={“Rectangle”,”Circle”};

    String inforonComponents;
    public Shape(){

    ListenForButton butt=new ListenForButton();

    JMenuBar jmb=new JMenuBar();

    JComboBox anyshape=new JComboBox(newx);

    Container cm=getContentPane();
    cm.setLayout(new BorderLayout(50,250));

    cm.add(new JButton(“Select”),BorderLayout.SOUTH);

    setJMenuBar(jmb);
    fileMenu=new JMenu(“File”);
    jmb.add(fileMenu);
    cm.add(anyshape,BorderLayout.WEST);

    JMenu fileMenu=new JMenu(“File”);
    JMenu file=new JMenu(“file”);
    JMenuItem jExit=new JMenu(“Exit”);

    this.fileMenu.add(file);

    JMenuItem JExit=new JMenuItem(“Exit”);

    this.fileMenu.add(JExit);
    JMenuItem JOpen=new JMenuItem(“Open”);
    JMenuItem JSave=new JMenuItem(“Save”);
    file.add(JOpen);
    file.add(JSave);

    button.addActionListener(butt);

    setTitle(“choose”);
    setSize(300,400);
    setVisible(true);
    setLocationRelativeTo(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public static void main(String []args){

    Shape a=new Shape();

    }

    private class ListenForButton implements ActionListener {
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==button)
    anyshape.setEditable(true);

    inforonComponents=”Item at 0 : “+anyshape.getSelectedIndex()+”\n”;

    inforonComponents=”Item at 0 : “+anyshape.isEditable()+”\n”;

    JOptionPane.showMessageDialog(Shape.this, inforonComponents, “Information”, JOptionPane.INFORMATION_MESSAGE);

    }
    }

    }

Leave a Reply

Your email address will not be published.

Google+