Topic: SOS!!! 不知道问题出在哪里?多谢帮忙

  Print this page

1.SOS!!! 不知道问题出在哪里?多谢帮忙 Copy to clipboard
Posted by: king431
Posted on: 2005-09-06 18:32

import java.awt.*;
import java.awt.event.*;

public class Dialog extends Frame implements ActionListener
{
   Button btnExit;
   Button btnYes;
   Button btnNo;
   Dialog dlgConfirm;
   public Dialog()
   {
     btnExit=new Button("Eixt");
     btnExit.addActionListener(this);
     
     add(btnExit);
     setLayout(new FlowLayout());
     
     dlgConfirm=new Dialog();
     dlgConfirm.setResizable(false);
     
     btnYes=new Button("Y");
     btnYes.addActionListener(this);
     
     btnNo=new Button("N");
     btnNo.addActionListener(this);
     
     dlgConfirm.add(btnYes);
     dlgConfirm.add(btnNo);
dlgConfirm.setTitle("SY?");

dlgConfirm.setSize(200,100);
dlgConfirm.setLayout(new FlowLayout());

addWindowListener(new WinCloser());
setTitle("Using a Dialog");
setBounds(100,100,300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
  if(ae.getActionCommand().equals("Exit"))
   dlgConfirm.show();
  if(ae.getActionCommand().equals("Y"))
   System.exit(0);
  if(ae.getActionCommand().equals("N"))
   dlgConfirm.setVisible(false);
}
public static void main(String[] args)
{
  Dialog td=new Dialog();
}
}
class WinCloser extends WindowAdapter
{
  public void WindowClosing(WindowEvent e)
  {
    System.exit(0);
  }
}

2.Re:SOS!!! 不知道问题出在哪里?多谢帮忙 [Re: king431] Copy to clipboard
Posted by: why
Posted on: 2005-09-06 19:31

请尽量使用准确的文字描述作为标题
若新帖再無恰当标题,將会被刪除



> btnExit=new Button("Eixt");
typo : Exit

> Dialog dlgConfirm;
> ...
> dlgConfirm=new Dialog();
I guess you're trying to use java.awt.Dialog. You chose a poor name for the class (rename it MyDialog or so for clarity)
And it should be:
dlgConfirm=new java.awt.Dialog(this); // check the Java API

3.Re:SOS!!! 不知道问题出在哪里?多谢帮忙 [Re: king431] Copy to clipboard
Posted by: q_yuan
Posted on: 2005-09-07 08:46

你这个程序写得很混乱,我修改了一下你的。你看是不是你所要的:
import java.awt.*;
import java.awt.event.*;

public class Dialog extends Frame implements ActionListener
{
Button btnExit;
Button btnYes;
Button btnNo;
public Dialog()
{
btnExit=new Button("Eixt");
btnExit.addActionListener(this);
setResizable(false);

btnYes=new Button("Y");
btnYes.addActionListener(this);

btnNo=new Button("N");
btnNo.addActionListener(this);
btnYes.setBounds(new Rectangle(10,40,60,20));
btnNo.setBounds(new Rectangle(10,100,60,20));
btnExit.setBounds(new Rectangle(10,200,60,20));
this.setLayout(null);
this.add(btnYes,null);
this.add(btnNo,null);
this.add(btnExit,null);
addWindowListener(new WinCloser());
setTitle("Using a Dialog");
setBounds(100,100,300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
   Dialog dlgConfirm = new Dialog();

if(ae.getActionCommand().equals("Exit"))
dlgConfirm.show();
if(ae.getActionCommand().equals("Y"))
System.exit(0);
if(ae.getActionCommand().equals("N"))
dlgConfirm.setVisible(false);
}
public static void main(String[] args)
{
new Dialog();
}
}
class WinCloser extends WindowAdapter
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}

4.Re:SOS!!! 不知道问题出在哪里?多谢帮忙 [Re: king431] Copy to clipboard
Posted by: king431
Posted on: 2005-09-08 19:07

谢谢你们!!!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923