Java点击按钮弹出对话框的代码如何编写?

2026-06-05 20:5812阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计670个文字,预计阅读时间需要3分钟。

Java点击按钮弹出对话框的代码如何编写?

java[求助] 如何改才能当点击按钮时才会弹出对话框?import java.awt.*;import java.awt.event.*;

public class MyProject extends JFrame { private JButton button;

public MyProject() { // 设置窗口和默认关闭操作 setTitle(弹窗示例); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置布局管理器 setLayout(new FlowLayout());

// 创建按钮并添加事件监听器 button=new JButton(点击我); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MyProject.this, 对话框弹出!); } }); // 添加按钮到窗口 add(button);

// 设置窗口大小并使其可见 setSize(300, 200); setVisible(true); }

public static void main(String[] args) { new MyProject(); }}

[求助]要怎么改才能当点按钮时才会弹出对话框?importjava.awt.*;importjava.awt.event.*;publicclassMyprojectextends

[求助]要怎么改才能当点按钮时才会弹出对话框?

import java.awt.*;

import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {

public static void main(String args[]) {

TextArea ta;

Button button;

Frame fr new Frame("KOF");

ta new TextArea();

fr.add(ta,BorderLayout.CENTER);

button new Button("读取");

fr.add(button,BorderLayout.SOUTH);

//button.addActionListene(this);

fr.setSize(200,100);

fr.setVisible(true);

FileDialog dialog new FileDialog(fr,"My FileDialog");

dialog.setVisible(true);

String fname dialog.getDirectory() dialog.getFile();

fr.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent event) {

Object dialog null;

if(dialog null) {

dialog new FileDialog(this,"My FileDialog");

}

((Component) dialog).setVisible(true);

}

public Myproject(String str) {

super(str);

}

}

Java点击按钮弹出对话框的代码如何编写?

请问要怎么改才能当自己点按钮的时候才会弹出对话框 ,修改以后请给我全部代码.多谢!!

搜索更多相关的解决方案:

对话框  按钮

----------------解决方案--------------------------------------------------------

import java.awt.*;

import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {

public static void main(String args[]) {

new Myproject();

}

private FileDialog dialog;

private Button button;

private TextArea ta;

Myproject(){

Frame fr new Frame("KOF");

ta new TextArea();

fr.add(ta,BorderLayout.CENTER);

button new Button("读取");

fr.add(button,BorderLayout.SOUTH);

button.addActionListener(this);

fr.setSize(200,100);

fr.setVisible(true);

dialog new FileDialog(fr,"My FileDialog");

dialog.setVisible(false);

fr.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent event) {

if(event.getSource()button){

dialog.setVisible(true);

String fname dialog.getDirectory() dialog.getFile();

ta.setText(fname);

}

}

}

[此贴子已经被作者于2006-6-11 22:08:11编辑过]

----------------解决方案--------------------------------------------------------

多谢myfor...请问你QQ多少啊??我加你..我还有很多JAVA问题请教!!!!我的是412222975

----------------解决方案--------------------------------------------------------

本文共计670个文字,预计阅读时间需要3分钟。

Java点击按钮弹出对话框的代码如何编写?

java[求助] 如何改才能当点击按钮时才会弹出对话框?import java.awt.*;import java.awt.event.*;

public class MyProject extends JFrame { private JButton button;

public MyProject() { // 设置窗口和默认关闭操作 setTitle(弹窗示例); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置布局管理器 setLayout(new FlowLayout());

// 创建按钮并添加事件监听器 button=new JButton(点击我); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MyProject.this, 对话框弹出!); } }); // 添加按钮到窗口 add(button);

// 设置窗口大小并使其可见 setSize(300, 200); setVisible(true); }

public static void main(String[] args) { new MyProject(); }}

[求助]要怎么改才能当点按钮时才会弹出对话框?importjava.awt.*;importjava.awt.event.*;publicclassMyprojectextends

[求助]要怎么改才能当点按钮时才会弹出对话框?

import java.awt.*;

import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {

public static void main(String args[]) {

TextArea ta;

Button button;

Frame fr new Frame("KOF");

ta new TextArea();

fr.add(ta,BorderLayout.CENTER);

button new Button("读取");

fr.add(button,BorderLayout.SOUTH);

//button.addActionListene(this);

fr.setSize(200,100);

fr.setVisible(true);

FileDialog dialog new FileDialog(fr,"My FileDialog");

dialog.setVisible(true);

String fname dialog.getDirectory() dialog.getFile();

fr.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent event) {

Object dialog null;

if(dialog null) {

dialog new FileDialog(this,"My FileDialog");

}

((Component) dialog).setVisible(true);

}

public Myproject(String str) {

super(str);

}

}

Java点击按钮弹出对话框的代码如何编写?

请问要怎么改才能当自己点按钮的时候才会弹出对话框 ,修改以后请给我全部代码.多谢!!

搜索更多相关的解决方案:

对话框  按钮

----------------解决方案--------------------------------------------------------

import java.awt.*;

import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {

public static void main(String args[]) {

new Myproject();

}

private FileDialog dialog;

private Button button;

private TextArea ta;

Myproject(){

Frame fr new Frame("KOF");

ta new TextArea();

fr.add(ta,BorderLayout.CENTER);

button new Button("读取");

fr.add(button,BorderLayout.SOUTH);

button.addActionListener(this);

fr.setSize(200,100);

fr.setVisible(true);

dialog new FileDialog(fr,"My FileDialog");

dialog.setVisible(false);

fr.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent event) {

if(event.getSource()button){

dialog.setVisible(true);

String fname dialog.getDirectory() dialog.getFile();

ta.setText(fname);

}

}

}

[此贴子已经被作者于2006-6-11 22:08:11编辑过]

----------------解决方案--------------------------------------------------------

多谢myfor...请问你QQ多少啊??我加你..我还有很多JAVA问题请教!!!!我的是412222975

----------------解决方案--------------------------------------------------------