Skip to content

Commit d852b12

Browse files
committed
6th lab code added
1 parent 06ff38a commit d852b12

15 files changed

+184
-0
lines changed

java-6th/Dialog$1.class

630 Bytes
Binary file not shown.

java-6th/Dialog$2.class

631 Bytes
Binary file not shown.

java-6th/Dialog.class

1.64 KB
Binary file not shown.

java-6th/MyDialog$1.class

616 Bytes
Binary file not shown.

java-6th/MyDialog.class

1.09 KB
Binary file not shown.

java-6th/MyOwnDialog.class

1.02 KB
Binary file not shown.

java-6th/MyOwnDialog.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import javax.swing.*;
2+
import java.awt.event.*;
3+
import java.awt.*;
4+
class MyOwnDialog extends JFrame implements ActionListener{
5+
JButton btn;
6+
7+
public MyOwnDialog(){
8+
btn = new JButton("click");
9+
setSize(400, 500);
10+
//setLayout(null); no need to do as we have added BoxLayout there in class MyDialog
11+
add(btn);
12+
btn.addActionListener(this);
13+
setVisible(true);
14+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15+
}
16+
public void actionPerformed(ActionEvent e){
17+
//adding own JPopupDialog MyDialog with it's static function showMessageDialog with the same argumenst passed in the function.
18+
MyDialog.showMessageDialog(this, "This is warning message !", "message-dialog", JOptionPane.WARNING_MESSAGE);
19+
}
20+
public static void main(String [] args){
21+
new MyOwnDialog();
22+
}
23+
}
24+
class MyDialog{
25+
//Static variable is the one that is common to all the instances of the class.
26+
//A single copy of the variable is shared among all objects.
27+
static JDialog d;
28+
static JLabel l;
29+
static JButton b;
30+
31+
public static void showMessageDialog(JFrame frame, String msg, String title, int type_of_message){
32+
d = new JDialog(frame, title);
33+
l = new JLabel(msg);
34+
b = new JButton("ok");
35+
d.setSize(200, 120);
36+
d.setLayout(new BoxLayout(d.getContentPane(),BoxLayout.Y_AXIS));
37+
b.setAlignmentX(Component.CENTER_ALIGNMENT);
38+
l.setAlignmentX(Component.CENTER_ALIGNMENT);
39+
d.add(Box.createRigidArea(new Dimension(0, 10)));
40+
d.add(l);
41+
d.add(Box.createRigidArea(new Dimension(0, 10)));
42+
d.add(b);
43+
d.setLocationRelativeTo(frame);
44+
d.setVisible(true);
45+
b.addActionListener(new ActionListener(){
46+
public void actionPerformed(ActionEvent e){
47+
d.setVisible(false);
48+
}
49+
});
50+
}
51+
}

java-6th/MyOwnDialogWithRadio.class

1.56 KB
Binary file not shown.

java-6th/MyOwnDialogWithRadio.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import javax.swing.*;
2+
import java.awt.event.*;
3+
import java.awt.*;
4+
5+
public class MyOwnDialogWithRadio extends JFrame implements ActionListener {
6+
7+
JRadioButton se, it;
8+
9+
public MyOwnDialogWithRadio(){
10+
se = new JRadioButton("SE", true);
11+
it = new JRadioButton("IT");
12+
setSize(300, 400);
13+
add(se);
14+
add(it);
15+
ButtonGroup bg = new ButtonGroup();
16+
bg.add(se);
17+
bg.add(it);
18+
se.addActionListener(this);
19+
it.addActionListener(this);
20+
setLayout(new FlowLayout(FlowLayout.CENTER));
21+
setVisible(true);
22+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
23+
}
24+
public void actionPerformed(ActionEvent e){
25+
Object source = e.getSource();
26+
if(source == se)
27+
JOptionPane.showMessageDialog(this, "You have selected the software field", "SE-III", JOptionPane.WARNING_MESSAGE);
28+
else
29+
JOptionPane.showMessageDialog(this, "You have selected an IT field", "IT-III", JOptionPane.ERROR_MESSAGE);
30+
}
31+
public static void main(String [] args){
32+
new MyOwnDialogWithRadio();
33+
}
34+
}
35+
class MyDialog{
36+
static JDialog d;
37+
static JLabel l;
38+
static JButton b;
39+
40+
public static void showMessageDialog(JFrame frame, String msg, String title, int type_of_message){
41+
d = new JDialog(frame, title);
42+
l = new JLabel(msg);
43+
b = new JButton("ok");
44+
d.setSize(200, 100);
45+
d.setLayout(new BoxLayout(d.getContentPane(), BoxLayout.Y_AXIS));
46+
d.setVisible(true);
47+
b.addActionListener(new ActionListener(){
48+
public void actionPerformed(ActionEvent e){
49+
d.setVisible(true);
50+
}
51+
});
52+
}
53+
}

java-6th/OwnDialog.class

1005 Bytes
Binary file not shown.

java-6th/OwnDialog.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import javax.swing.*;
2+
import java.awt.event.*;
3+
import java.awt.*;
4+
class OwnDialog extends JFrame implements ActionListener{
5+
JButton btn;
6+
7+
public OwnDialog(){
8+
btn = new JButton("click");
9+
setSize(400, 500);
10+
//setLayout(null); no need to do as we have added BoxLayout there in class Dialog
11+
add(btn);
12+
btn.addActionListener(this);
13+
setVisible(true);
14+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15+
}
16+
public void actionPerformed(ActionEvent e){
17+
//adding own JPopupDialog Dialog with it's static function showMessageDialog with the same argumenst passed in the function.
18+
Dialog.showConfirmeDialog(this, "This is warning message !", "message-dialog");
19+
}
20+
public static void main(String [] args){
21+
new OwnDialog();
22+
}
23+
}
24+
class Dialog{
25+
//Static variable is the one that is common to all the instances of the class.
26+
//A single copy of the variable is shared among all objects.
27+
28+
static JDialog d;
29+
static JLabel l;
30+
static JButton btn_f, btn_s;
31+
32+
public static boolean showConfirmeDialog(JFrame frame, String msg, String title){
33+
d = new JDialog(frame, title);
34+
l = new JLabel(msg);
35+
btn_f = new JButton("Ok");
36+
btn_s = new JButton("Cancel");
37+
d.setSize(200, 180);
38+
d.setLayout(new BoxLayout(d.getContentPane(),BoxLayout.Y_AXIS));
39+
btn_f.setAlignmentX(Component.CENTER_ALIGNMENT);
40+
btn_s.setAlignmentX(Component.CENTER_ALIGNMENT);
41+
l.setAlignmentX(Component.CENTER_ALIGNMENT);
42+
d.add(Box.createRigidArea(new Dimension(0, 10)));
43+
d.add(l);
44+
d.add(Box.createRigidArea(new Dimension(0, 10)));
45+
d.add(btn_f);
46+
d.add(Box.createRigidArea(new Dimension(0, 10)));
47+
d.add(btn_s);
48+
d.setLocationRelativeTo(frame);
49+
d.setVisible(true);
50+
btn_f.addActionListener(new ActionListener(){
51+
public void actionPerformed(ActionEvent e){
52+
String ans = "true";
53+
l.setText(ans);
54+
55+
}
56+
});
57+
btn_s.addActionListener(new ActionListener(){
58+
public void actionPerformed(ActionEvent e){
59+
String ans = "false";
60+
l.setText(ans);
61+
}
62+
});
63+
return true;
64+
}
65+
66+
}

java-6th/myowndailog02.png

25.8 KB
Loading

java-6th/myowndialog22.png

23.3 KB
Loading

java-6th/myowndialogwithRadio24.png

15.6 KB
Loading

java-6th/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# `Programming Questions of lab 6`
2+
3+
**Question no. 1:- Write a Java Program to create your own JOptionPane that shows the normal messageDialog.**
4+
5+
Answer:- MyOwnDialog.java
6+
7+
![CHESSE!](myowndialog22.png)
8+
9+
10+
**Question no. 2:- Write a Java Program to create your own JOptionPane that shows the normal messageDialog in which display the result what the user have selectd either SE or IT by making the two RadioButtons se and it.**
11+
12+
Answer:- MyOwnDialogWithRadio.java
13+
14+
![CHEESE!](myowndialogwithRadio24.png)

0 commit comments

Comments
 (0)