Can someobody tell me why i only see blank window.

import java.awt.*;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;



public class dic extends JFrame{
public JLabel label1,label2,label3,label4,label5,titlel;
public JTextField ew,fw;
public JTextArea txar1,txar2;
public JPanel panel1,panel2,panel3,panel5;


public JScrollPane scr1,scr2;
public GridBagLayout layout1,layout2,layout3,layout4;
public JTabbedPane tab1=new JTabbedPane();
public JButton exit,ok,insert,clear,delete;

      dichash has=new dichash(26);
    public dic(){



        exit=new JButton("exit");

        exit.setToolTipText("u will lost all data");


      panel1=new JPanel();
      panel1.setLayout(layout1);
        ok=new JButton("ok");
        insert=new JButton("insert");
        clear=new JButton("clear");
        delete=new JButton("delete");
        delete.setToolTipText("warning word will delete");

       label2=new JLabel("enter word do u want to find");
       label3=new JLabel("enter the word");
       label4=new JLabel("description");
       label5=new JLabel(new ImageIcon (getClass().getResource("2.gif")));

       panel2=new JPanel();
       panel2.setLayout(layout2);

       JScrollPane scr1=new JScrollPane();
       scr1=new JScrollPane(scr1.createHorizontalScrollBar());
       scr1=new JScrollPane(scr1.createVerticalScrollBar());
       scr1.setBackground(Color.yellow);
       panel3=new JPanel();
       panel3.setLayout(layout3);
       panel5=new JPanel();
       panel5.setLayout(layout4);

       JScrollPane scr2=new JScrollPane();
       scr2=new JScrollPane(scr2.createHorizontalScrollBar());
       scr2= new JScrollPane(scr2.createVerticalScrollBar());
       JTextField ew=new JTextField();
       JTextArea txar1=new JTextArea();
       JTextArea txar2=new JTextArea();
       JTextField fw=new JTextField();
       this.getContentPane().setLayout(layout1);

       tab1.add(panel1, "about");

       this.getContentPane().add(tab1,new GridBagConstraints(0,0,1,1,1.0,1.0
             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 4, 5, 4), -2, -1));

       tab1.add(panel2, "Search");
       tab1.add(panel3, "Enter");
       panel1.add(label5, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 282), 135, 101));


       panel1.add(exit, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46, 63, 50, 0), 49, 4));


       exit.addActionListener(new java.awt.event.ActionListener(){

           public void actionPerformed(ActionEvent e){
               exit_ActionPerformed(e);
           }


               }
       );



       panel2.add(label2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 14, 0, 0), 8, 25));

       panel2.add(ok,new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 14, 9, 13), 24, 1));
       ok.addActionListener(new java.awt.event.ActionListener(){

           public void actionPerformed(ActionEvent e){
               ok_ActionPerformed(e);
           }
       }

       );

       panel2.add(scr1,new GridBagConstraints(0, 1, 3, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 6, 3, 0), 532, 238));
       panel2.add(ew,new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(16, 6, 6, 0), 222, 12));
       panel3.add(fw,  new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(22, 29, 0, 167), 164, 4));
       panel3.add(scr2,new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(32, 18, 0, 62), 378, 105));
       panel3.add(label3,new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(22, 17, 0, 0), 18, 10));
panel3.add(label4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(85, 20, 60, 0), 27, 12));

panel3.add(panel5, new GridBagConstraints(1, 2, 2, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 16, 5, 120), 0, 47));
panel5.add(insert,new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 15, 24, 0), 27, 9));
insert.addActionListener(new java.awt.event.ActionListener() {


            public void actionPerformed(ActionEvent e) {
                insert_ActionPerformed(e);
            }
        }
        );

        panel5.add(delete, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 11, 24, 26), 23, 9));

        delete.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
               delete_ActionListener(e);
 }
        });
        panel5.add(clear,new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 12, 24, 0), 35, 8));
        clear.addActionListener(new java.awt.event.ActionListener(){
            public void actionPerformed(ActionEvent e){
                clear_ActionPerformed(e);
            }
        });

        scr1.getViewport().add(txar1,null);
        scr2.getViewport().add(txar2,null);










    }
    void  exit_ActionPerformed(ActionEvent e){
       System.exit(0);

}
 void ok_ActionPerformed(ActionEvent e){
     if (ew.getText().equals(""))
         txar1.setText(has.getTable());
     else{
        String del=ew.getText();



             {
                 Node n=has.Find(del);
                 if(n==null)
         txar1.setText("nothing to view");
                 else
                 {
                  String w=n.word;
         String m=n.masg;
           txar1.setText(w+"=="+m);

             }


             }

 }
 }

    void insert_ActionPerformed(ActionEvent e){
        if (fw.getText().equals("") || txar2.getText().equals("") )
            txar2.setText("enter both word and description");

    else
    {
        has.insert(fw.getText(), txar2.getText());
        fw.setText("");
        txar2.setText("");

    }
}

void delete_ActionListener(ActionEvent e){
    String del=fw.getText();

    if(del.equals(""))
    txar2.setText("nothing to deletete");
    else

    {
        Node n=has.Find(del);
        if(n==null)
            txar2.setText("word not include");
        else if
        (has.deletword(del));
        txar2.setText("successfully deleted");
}
}
void clear_ActionPerformed(ActionEvent e){
    fw.setText("");
    txar2.setText("");

}


    public static void main(String[] args) {
        dic main=new dic();
        main.setSize(600,400);
        main.setVisible(true);
        main.pack();

  }
}

Recommended Answers

All 4 Replies

You never initialise your layout variables (line 24), so all your panels have a null layout manager.

ps: all this padding and boilerplate

       exit.addActionListener(new java.awt.event.ActionListener(){
           public void actionPerformed(ActionEvent e){
               exit_ActionPerformed(e);
           }
               }
       );

can now be replaced with

exit.addActionListener(this::exit_ActionPerformed);

i fix that but why only exit button is working in my whole program. everything looks fine to me.thanks

import java.awt.*;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
import javax.swing.event.AncestorEvent;
    public class dic extends JFrame{
    public JLabel label2,label3,label4,label5;
    public JTextField ew,fw;
    public JTextArea txar1,txar2;
    public JPanel panel1,panel2,panel3,panel5;
    public JScrollPane scr1,scr2;
    public GridBagLayout layout1,layout2,layout3,layout4;
    public JTabbedPane tab1=new JTabbedPane();
    public JButton exit,ok,insert,clear,delete;
    dichash has=new dichash(26);

    public dic(){
        GridBagLayout layout1=new GridBagLayout();
GridBagLayout layout2=new GridBagLayout();
GridBagLayout layout3=new GridBagLayout();
GridBagLayout layout4=new GridBagLayout();

    exit=new JButton("exit");
    exit.setToolTipText("u will lost all data");
    panel1=new JPanel();
    panel1.setLayout(layout1);
    ok=new JButton("ok");
    insert=new JButton("insert");
    clear=new JButton("clear");
    delete=new JButton("delete");
    delete.setToolTipText("warning word will delete");
    label2=new JLabel("enter word do u want to find");
    label3=new JLabel("enter the word");
    label4=new JLabel("description");
    label5=new JLabel(new ImageIcon (getClass().getResource("2.gif")));
    panel2=new JPanel();
    panel2.setLayout(layout2);
    JScrollPane scr1=new JScrollPane();
    scr1=new JScrollPane(scr1.createHorizontalScrollBar());
    scr1=new JScrollPane(scr1.createVerticalScrollBar());
    scr1.setBackground(Color.yellow);
    panel3=new JPanel();
    panel3.setLayout(layout3);
    panel5=new JPanel();
    panel5.setLayout(layout4);
    JScrollPane scr2=new JScrollPane();
    scr2=new JScrollPane(scr2.createHorizontalScrollBar());
    scr2= new JScrollPane(scr2.createVerticalScrollBar());
    JTextField ew=new JTextField();
    JTextArea txar1=new JTextArea();
    JTextArea txar2=new JTextArea();
    JTextField fw=new JTextField();
    this.getContentPane().setLayout(layout1);
    tab1.add(panel1, "about");
    this.getContentPane().add(tab1,new GridBagConstraints(0,0,1,1,1.0,1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 4, 5, 4), -2, -1));
    tab1.add(panel2, "Search");
    tab1.add(panel3, "Enter");
    panel1.add(label5, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 282), 135, 101));
    panel1.add(exit, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46, 63, 50, 0), 49, 4));
    exit.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e){
    exit_ActionPerformed(e);
    }
    }
    );
    panel2.add(label2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 14, 0, 0), 8, 25));
    panel2.add(ok,new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 14, 9, 13), 24, 1));
    ok.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e){
    ok_ActionPerformed(e);
    }
    }
    );
    panel2.add(scr1,new GridBagConstraints(0, 1, 3, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 6, 3, 0), 532, 238));
    panel2.add(ew,new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(16, 6, 6, 0), 222, 12));
    panel3.add(fw, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(22, 29, 0, 167), 164, 4));
    panel3.add(scr2,new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(32, 18, 0, 62), 378, 105));
    panel3.add(label3,new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(22, 17, 0, 0), 18, 10));
    panel3.add(label4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(85, 20, 60, 0), 27, 12));
    panel3.add(panel5, new GridBagConstraints(1, 2, 2, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 16, 5, 120), 0, 47));
    panel5.add(insert,new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 15, 24, 0), 27, 9));
    insert.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    insert_ActionPerformed(e);
    }
    }
    );
    panel5.add(delete, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 11, 24, 26), 23, 9));
    delete.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    delete_ActionPerformed(e);
    }
    });
    panel5.add(clear,new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 12, 24, 0), 35, 8));
    clear.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e){
    clear_ActionPerformed(e);
    }
    });

    txar1.addAncestorListener(new javax.swing.event.AncestorListener() {
      public void ancestorAdded(AncestorEvent e) {
        txar1_ancestorAdded(e);
      }
      public void ancestorRemoved(AncestorEvent e) {
      }
      public void ancestorMoved(AncestorEvent e) {
      }
    });
    scr1.getViewport().add(txar1,null);
    scr2.getViewport().add(txar2,null);
    }
   void exit_ActionPerformed(ActionEvent e){
    System.exit(0);
    }
    void ok_ActionPerformed(ActionEvent e){
    if (ew.getText().equals(""))
    txar1.setText(has.getTable());
    else {
        Node n=has.Find(ew.getText().toLowerCase());
        if(n==null){txar1.setText("Nothing to view");}
        else{
         String w=n.word;
         String m=n.masg;
           txar1.setText(w+"=="+m);
         }
       }
   }
    void insert_ActionPerformed(ActionEvent e){
    if (fw.getText().equals("") || txar2.getText().equals("") )
    txar2.setText("enter both word and description");
    else
    {
    has.insert(fw.getText().toLowerCase(), txar2.getText());
    fw.setText("");
    txar2.setText("");
    }
    }
    void delete_ActionPerformed(ActionEvent e){
    String del=fw.getText().toLowerCase();
    if(del.equals(""))
    txar2.setText("nothing to delete");
    else
    {
    Node n=has.Find(del);
    if(n==null)
    txar2.setText("word not included");
    else if
    (has.deletword(del));
    txar2.setText("successfully deleted");
    }
    }
    void clear_ActionPerformed(ActionEvent e){
    fw.setText("");
    txar2.setText("");
    }
   void txar1_ancestorAdded(AncestorEvent e) {
     txar1.setText(has.getTable());
  }

    public static void main(String[] args) {
    dic main=new dic();
    main.setSize(600,400);
    main.setVisible(true);
    main.pack();
     main.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
            System.exit(1);}});
    }
    }

another issue is scr1.getViewport().add(txar1,null);, don't to use JViewport as container, for more info to read Oracle tutorial - How to Use Scroll Panes

You don't say what's wrong with the other buttons. Are the action listener methods being called? (You can add a print statement as the first line in the listener to check that)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.