File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.Error: Unresolved compilation problem: ModalityType cannot be resolved

 
rohan gaur
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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]
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic