JDialog

Hi everyone,Although, I made research about JDialog, I now do not have enough knowledge to use this container. I am also searching for a simple code snippet which basically explainhow dialog is used.So if you have, please post it here.Thanks,Mert
[281 byte] By [samue-1a] at [2007-10-2 17:23:18]
# 1
Maybe this from the Swing Tutorial? http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
nbloma at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 2
> Maybe this from the Swing Tutorial?> > http://java.sun.com/docs/books/tutorial/uiswing/compon> ents/dialog.htmlI know this but there is no a small program which show how to create a dialog.
samue-1a at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 3

>

> I know this but there is no a small program which

> show how to create a dialog.

Do you know how to use a JFrame? Cause JDialogs are similar to JFrames except for the ability to be modal.

I guess I need more information to help you. What are you trying to do? Are you trying to show a message box or design a full-fledged application?

nbloma at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 4

Thanks for your interest firstly.

Then I only want to learn how JDialog can be created simply.

Do you have a small program that shows me the basic usage of it

I mean that I wan to see which methods , fiedls or even constructor do we use to generate a basic JDialog.

Meanwhile, Yes I know how to create frame

samue-1a at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 5
Are you trying to show a message box or design a full-fledged application?This simple things . I want to see how can this happen.
samue-1a at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 6

Well, the api is basically the same as a JFrame. You add components via getContentPane().add(...).

To show a simple message to the user do this:

JOptionPane.showMessageDialog(null,"This is a test message!");

More complicated (error message):

JOptionPane.showMessageDialog(null,"This is a test (error) message!","Title of Error Message!",JOptionPane.ERROR_MESSAGE);

Change the nulls to the parent component you are working with.

Notice that here I used JOptionPane to display these "simple" dialogs.

JDialog is used when you want a window to be modal in front of another. JFrame is used basically as an independent window.

nbloma at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 7

import java.awt.event.*;

import java.awt.Color.*;

import javax.swing.*;

import javax.swing.border.*;

import javax.swing.border.*;

import java.io.*;

//import javax.swing.LayoutManager.*;

class FinalSales implements ActionListener

{

JFrame jf1;

JTabbedPane main = new JTabbedPane();

JButton btnLogoff;

//JButton =new JButton("LogOff");

//Purchase Form

JDialog d1;

JPanel jp,jp1,jp2;

//GridLayout gl=new GridLayout(1,1);

FinalSales()

{

jf1=new JFrame("Vision Tech software");

jp=new JPanel();

jp1=new JPanel();

jp2=new JPanel();

d1=new JDialog(jf1,true);

jp1.setLayout(new GridLayout(2,1));

btnLogoff=new JButton("LogOff");

btnLogoff.addActionListener(this);

jp1.add(btnLogoff);

main.addTab("Purhase",null,jp1,"Login Details Info");

main.addTab("sample",null,jp2,"Login Details Info");

//jp.add(jp1);

//jp.add(jp2);

d1.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

JDialog.setDefaultLookAndFeelDecorated(false);

d1.add(main);

//Purchase Form

//GridLayout gl=new GridLayout(1,1);

//jp1.setLayout(new BoxLayout(jp1,BoxLayout.PAGE_AXIS));

//jp1.setLayout(gl);

jp1.add(new JLabel("Purchase Form",JLabel.CENTER));

//d1.setContentPane(jp);

d1.setSize(500,500);

d1.setLocationRelativeTo(null);

d1.setResizable(false);

d1.setVisible(true);

//Action Listeners

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==btnLogoff)

{

System.out.println("hellow");

int choice = JOptionPane.showConfirmDialog (d1,

"Do you really want to Log-Off" ,

"Confirm LogOff" , JOptionPane.YES_NO_OPTION);

if(choice==JOptionPane.YES_OPTION)

d1.dispose();

System.exit(0);

//FinalMobile ml=new FinalMobile();

//jf1.setEnabled(true);

}

}

public static void main(String args[])

{

new FinalSales();

}

}

this code will help you

its jst the basic

Nadya at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 8
Thanks for this small program...Best wishes,Mert
samue-1a at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 9

Hi,

The below codes that belongs to the above program makes me a little bit confused. Can any of you please explain it ?

int choice = JOptionPane.showConfirmDialog (d1,

"Do you really want to Log-Off" ,

"Confirm LogOff" , JOptionPane.YES_NO_OPTION);

if(choice==JOptionPane.YES_OPTION)

d1.dispose();

System.exit(0);

//FinalMobile ml=new FinalMobile();

//jf1.setEnabled(true);

samue-1a at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...
# 10

Guys, why do you keep answering his questions.

Every time he posts a question the thread grows to 20 responses because he keeps asking silly questions like the one above.

His has been given a link to the Swing tutorial and asked to read it. Yet he refuses to do so.

There are examples in the tutorial on using dialogs and JOptionPanes. But he refuses to read up on them.

So don't waste your time helping him until he helps himself.

camickra at 2007-7-13 18:39:31 > top of Java-index,Desktop,Core GUI APIs...