Results 1 to 2 of 2
  1. #1
    Ladamann is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default Trouble with JDialog

    Hi!
    This one compiles just fine, but here only the JLabel is visible cant get
    "add(new NyttDyr(),BorderLayout.SOUTH);" to work... Whats wrong??

    public NyHareDialog(JFrame foreldre){
    super(foreldre,"Registrer ny hare",true);
    add(new JLabel("Tast inn informasjon om ny hare:"),BorderLayout.NORTH);
    add(new NyttDyr(),BorderLayout.SOUTH);
    setLocationRelativeTo(null);
    //setSize(300,300);
    pack();
    }




    Here is rest of the code..

    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;


    class DyreRegister extends JFrame{
    public static void main(String[] args) {
    ForeldreVindu meny = new ForeldreVindu();
    meny.setSize(1000,300);
    meny.setLocationRelativeTo(null);
    meny.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    meny.setVisible(true);
    }//Main
    } //Programklasse




    class NyHareDialog extends JDialog{
    private Kontroll kontroll = new Kontroll();
    private boolean ok;

    public NyHareDialog(JFrame foreldre){
    super(foreldre,"Registrer ny hare",true);
    add(new JLabel("Tast inn informasjon om ny hare: "),BorderLayout.NORTH);
    add(new NyttDyr(),BorderLayout.SOUTH);
    setLocationRelativeTo(null);
    //setSize(300,300);
    pack();
    }




    private class KnappeLytterDialog implements ActionListener{
    public void actionPerformed(ActionEvent hendelse){
    String kommando = hendelse.getActionCommand();
    ok = kommando.equals("OK");
    setVisible(false);
    }//Metode
    }//Klassen KnappeLytterDialog



    private class NyttDyr extends JPanel{
    public void NyttDyr(){

    KnappeLytterDialog knappelytter = new KnappeLytterDialog();
    JButton okKnapp, avbrytKnapp;
    JPanel p1,p2,p3,p4,p5,p6;
    JLabel l1,l2,l3,l4,l5;
    JTextField t1,t2,t3,t4,t5;

    setLayout(new GridLayout(6,2));

    p1 = new JPanel();
    add(p1);
    l1 = new JLabel("Kjnn: ");
    p1.add(l1);
    t1 = new JTextField(10);
    p1.add(t1);
    String kjnn = t1.getText();

    p2 = new JPanel();
    add(p2);
    l2 = new JLabel("Lengde: ");
    p2.add(l2);
    t2 = new JTextField(10);
    p2.add(t2);
    String lengdeT = t2.getText();
    Double lengde = Double.parseDouble(lengdeT);


    p3 = new JPanel();
    add(p3);
    l3 = new JLabel("Vekt: ");
    p3.add(l3);
    t3 = new JTextField(10);
    p3.add(t3);
    String vektT = t3.getText();
    Double vekt = Double.parseDouble(vektT);


    p4 = new JPanel();
    add(p4);
    l4 = new JLabel("Sted: ");
    p4.add(l4);
    t4 = new JTextField(10);
    p4.add(t4);
    String sted = t4.getText();

    p5 = new JPanel();
    add(p5);
    l5 = new JLabel("Dato: ");
    p5.add(l5);
    t5 = new JTextField(10);
    p5.add(t5);
    String dato = t5.getText();


    p6 = new JPanel();
    add(p6);
    avbrytKnapp = new JButton("Avbryt");
    p6.add(avbrytKnapp);
    avbrytKnapp.addActionListener(knappelytter);

    okKnapp = new JButton("OK");
    p6.add(okKnapp);
    okKnapp.addActionListener(knappelytter);

    }//Metode
    }//Klassen



    public boolean visDialog(){
    setVisible(true);
    return ok;
    }



    }//Klassen NyHareDialog

    class ForeldreVindu extends JFrame{
    private NyHareDialog nyhareboks = new NyHareDialog(this);

    public ForeldreVindu(){
    KnappeLytterForeldre knappelytter = new KnappeLytterForeldre();
    JPanel p1,p2;
    JButton b1,b2,b3,b4,b5;
    setLayout(new GridLayout(2,1));
    p1 = new JPanel();
    add(p1); //Legger til i rutenettet til vindu
    p2 = new JPanel();
    add(p2); //Legger til i rutenettet til vindu
    p1.setLayout(new GridLayout(1,5,5,5));

    b1 = new JButton("Ny hare");
    p1.add(b1);
    b1.addActionListener(knappelytter);


    b2 = new JButton("Ny gaupe");
    p1.add(b2);
    b2.addActionListener(knappelytter);

    b3 = new JButton("Gjenfangst hare");
    p1.add(b3);
    b3.addActionListener(knappelytter);

    b4 = new JButton("Gjenfangst gaupe");
    p1.add(b4);
    b4.addActionListener(knappelytter);

    b5 = new JButton("Utskrift");
    p1.add(b5);
    b5.addActionListener(knappelytter);

    pack();
    }//PUBLIC ForeldreVindu



    private class KnappeLytterForeldre implements ActionListener{
    public void actionPerformed(ActionEvent hendelse){
    if(nyhareboks.visDialog()){
    System.out.println("Ok trykket.");

    }else{
    System.out.println("Avbryt trykket.");
    }//else
    }//metode
    }//klassen KnappeLytterForeldre

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Use the code tags to format your code correctly and maybe someone will take a look.

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. This isn't a SSCCE -- a large part of the code obviously isn't related to the stated problem.

    db

Similar Threads

  1. my JDialog doesn't want to resize as I say :P
    By patr1c1a in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 03:12 PM
  2. JDialog
    By Nuclear Mosquito in forum AWT / Swing
    Replies: 1
    Last Post: 07-06-2010, 04:27 PM
  3. JDialog
    By frenk_castle in forum AWT / Swing
    Replies: 3
    Last Post: 05-11-2010, 01:28 PM
  4. Close JDialog
    By sky in forum AWT / Swing
    Replies: 7
    Last Post: 11-16-2009, 07:01 PM
  5. help with jdialog
    By leonard in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2007, 06:37 AM

Posting Permissions

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