那个记事本中的字体是点击后弹出另外一个对话框,在里面设置好后确定即可,这应该如何实现我是这样编的
JMenuItems font = new JMenuItem("字体...");
font.addActionListener(new Handler1());
>>
class Handler1 implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource == font)
font_mode fm = new font_mode(this);
}
}class font_mode{
JDialog jd = null;
font_mode(JFrame f){
jDialog = new JDialog(f,"字体",true);
.....
.....
}
} 但是编译的时候老是说
D:\Java\java>javac NoteBook.java
NoteBook.java:363: cannot find symbol
symbol : constructor font_mode(NoteBook.Handler1)
location: class NoteBook.font_mode
font_mode fm = new font_mode(this);
^
1 error怎么回事,我网上看的一个例子很相似,但是它却可以,另附网上的那个例子import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JDialogDemo extends JFrame implements ActionListener{
public JDialogDemo(){
Container contentPane=this.getContentPane();
JButton jButton1=new JButton("显示对话框");
jButton1.addActionListener(this);
contentPane.add(jButton1);
this.setTitle("JDialogDemo");
this.setSize(300,300);
this.setLocation(400,400);
this.setVisible(true);
}
/* 响应窗体的按钮事件 */
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("显示对话框")){
HelloDialog hw=new HelloDialog(this);
}
}
/* 窗体按钮监听器 */
class HelloDialog implements ActionListener{
JDialog jDialog1=null; //创建一个空的对话框对象
HelloDialog(JFrame jFrame){
/* 初始化jDialog1
* 指定对话框的拥有者为jFrame,标题为"Dialog",当对话框为可视时,其他构件不能
* 接受用户的输入(静态对话框) */
jDialog1=new JDialog(jFrame,"Dialog",true);
//创建一个按钮对象,该对象被添加到对话框中
JButton jButton1=new JButton("关闭");
jButton1.addActionListener(this);
//将"关闭"按钮对象添加至对话框容器中
jDialog1.getContentPane().add(jButton1);
/* 设置对话框的初始大小 */
jDialog1.setSize(80,80);
/* 设置对话框初始显示在屏幕当中的位置 */
jDialog1.setLocation(450,450);
/* 设置对话框为可见(前提是生成了HelloDialog对象) */
jDialog1.setVisible(true);
}
//响应对话框中的按钮事件
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("关闭")){
// 以下语句等价于jDialog1.setVisible(false);
/* public void dispose()
* 释放由此 Window、其子组件及其拥有的所有子组件所使用的所有本机屏幕资源。
* 即这些 Component 的资源将被破坏,它们使用的所有内存都将返回到操作系统,
* 并将它们标记为不可显示。 */
jDialog1.dispose();
}
}
}
public static void main(String[] args){
JDialogDemo test=new JDialogDemo();
}
}
JMenuItems font = new JMenuItem("字体...");
font.addActionListener(new Handler1());
>>
class Handler1 implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource == font)
font_mode fm = new font_mode(this);
}
}class font_mode{
JDialog jd = null;
font_mode(JFrame f){
jDialog = new JDialog(f,"字体",true);
.....
.....
}
} 但是编译的时候老是说
D:\Java\java>javac NoteBook.java
NoteBook.java:363: cannot find symbol
symbol : constructor font_mode(NoteBook.Handler1)
location: class NoteBook.font_mode
font_mode fm = new font_mode(this);
^
1 error怎么回事,我网上看的一个例子很相似,但是它却可以,另附网上的那个例子import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JDialogDemo extends JFrame implements ActionListener{
public JDialogDemo(){
Container contentPane=this.getContentPane();
JButton jButton1=new JButton("显示对话框");
jButton1.addActionListener(this);
contentPane.add(jButton1);
this.setTitle("JDialogDemo");
this.setSize(300,300);
this.setLocation(400,400);
this.setVisible(true);
}
/* 响应窗体的按钮事件 */
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("显示对话框")){
HelloDialog hw=new HelloDialog(this);
}
}
/* 窗体按钮监听器 */
class HelloDialog implements ActionListener{
JDialog jDialog1=null; //创建一个空的对话框对象
HelloDialog(JFrame jFrame){
/* 初始化jDialog1
* 指定对话框的拥有者为jFrame,标题为"Dialog",当对话框为可视时,其他构件不能
* 接受用户的输入(静态对话框) */
jDialog1=new JDialog(jFrame,"Dialog",true);
//创建一个按钮对象,该对象被添加到对话框中
JButton jButton1=new JButton("关闭");
jButton1.addActionListener(this);
//将"关闭"按钮对象添加至对话框容器中
jDialog1.getContentPane().add(jButton1);
/* 设置对话框的初始大小 */
jDialog1.setSize(80,80);
/* 设置对话框初始显示在屏幕当中的位置 */
jDialog1.setLocation(450,450);
/* 设置对话框为可见(前提是生成了HelloDialog对象) */
jDialog1.setVisible(true);
}
//响应对话框中的按钮事件
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("关闭")){
// 以下语句等价于jDialog1.setVisible(false);
/* public void dispose()
* 释放由此 Window、其子组件及其拥有的所有子组件所使用的所有本机屏幕资源。
* 即这些 Component 的资源将被破坏,它们使用的所有内存都将返回到操作系统,
* 并将它们标记为不可显示。 */
jDialog1.dispose();
}
}
}
public static void main(String[] args){
JDialogDemo test=new JDialogDemo();
}
}
好像是语法错误