Adding in CS-115 coursework
This commit is contained in:
34
cs-115-test/src/DialogExample.java
Normal file
34
cs-115-test/src/DialogExample.java
Normal file
@@ -0,0 +1,34 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class DialogExample {
|
||||
private static JDialog dialog;
|
||||
|
||||
public DialogExample() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
dialog = new JDialog(frame, "New Dialog Box", true);
|
||||
dialog.setLayout(new FlowLayout());
|
||||
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
JButton button = new JButton("OK");
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
DialogExample.dialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.add(new JLabel("Click OK to Agree"));
|
||||
dialog.add(button);
|
||||
dialog.setSize(250, 250);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new DialogExample();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user