| Author |
java.lang.Error: Unresolved compilation problem: ModalityType cannot be resolved
|
rohan gaur
Greenhorn
Joined: Sep 16, 2010
Posts: 1
|
|
[color=darkblue][size=12]package swingdialogs;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
class AboutDialog extends JDialog {
public AboutDialog() {
setTitle("About Notes");
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
add(Box.createRigidArea(new Dimension(0, 10)));
ImageIcon icon = new ImageIcon("notes.png");
JLabel label = new JLabel(icon);
label.setAlignmentX(0.5f);
add(label);
add(Box.createRigidArea(new Dimension(0, 10)));
JLabel name = new JLabel("Notes, 1.23");
name.setFont(new Font("Serif", Font.BOLD, 13));
name.setAlignmentX(0.5f);
add(name);
add(Box.createRigidArea(new Dimension(0, 50)));
JButton close = new JButton("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
dispose();
}
});
close.setAlignmentX(0.5f);
add(close);
setModalityType(ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setSize(300, 200);
}
}
public class SimpleDialog extends JFrame {
public SimpleDialog() {
setTitle("Simple Dialog");
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenu help = new JMenu("Help");
help.setMnemonic(KeyEvent.VK_H);
JMenuItem about = new JMenuItem("About");
help.add(about);
about.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
AboutDialog ad = new AboutDialog();
ad.setVisible(true);
}
});
menubar.add(file);
menubar.add(help);
setJMenuBar(menubar);
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new SimpleDialog();
}
}
//////////////////////////////// In Class :: AboutDialog, while setting ModalityType ///////////////////////////////
Please, help me out to resolve out this problem ..[/size][/color]
|
Thanks & Regards,
Rohan Gaur
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
Welcome to the forum. UseCodeTags to post code so that it is readable. And to get better help sooner, always post a SSCCE. Your question is about a class that's not found. JMenus and ActionListeners and the like have nothing to do with your question and are just so much clutter when it comes to reading the code.
Dialog.ModalityType. Or import static ...Dialog.*; and you will be able to use the unqualified name in your code.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Dialog.ModalityType has been added in Java 6. Are you perhaps using an older version?
Also, never ever ever ever run code that still has compiler errors in it. Fix those first. Your IDE is showing you exactly what they are.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: java.lang.Error: Unresolved compilation problem: ModalityType cannot be resolved
|
|
|