如何编写源代码以查找“圆环区域"并与GUI一起显示?在java中 [英] How can I write source code to find Area of Circle and to display with GUI? in java

查看:137
本文介绍了如何编写源代码以查找“圆环区域"并与GUI一起显示?在java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*;
public class Frame3 extends JFrame implements ActionListener
{
  JLabel answer = new JLabel("");
  JPanel pane = new JPanel(); // create pane object
  JButton pressme = new JButton("Press Me");
  Frame3()   // the constructor
  {
    super("Event Handler Demo"); setBounds(100,100,300,200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    con.add(pane); pressme.setMnemonic('P'); // associate hotkey
    pressme.addActionListener(this);   // register button listener
    pane.add(answer); pane.add(pressme); pressme.requestFocus();
    setVisible(true); // make frame visible
  }
  // here is the basic event handler
  public void actionPerformed(ActionEvent event)
  {
    Object source = event.getSource();
    if (source == pressme)
    {
      answer.setText("Button pressed!");
      JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
      JOptionPane.PLAIN_MESSAGE); setVisible(true);  // show something
    }
  }
  public static void main(String args[]) {new Frame3();}
}

推荐答案

成员11308177写道:
Member 11308177 wrote:


JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); setVisible(true);  // show something

这让我想起了轶事

It reminds me the anecdote

一个心理分析师问另一个: —你能告诉我如何计算一个圆的面积吗?"
—想谈谈吗?"
One psychoanalyst asks another one:
— "Could you tell me how to calculate the area of a circle?"
— "Want to talk about it?"

让我提醒您:这是软件开发人员,工程师或学生的论坛.提出问题还具有一些先决条件:询问者应受过足够的教育,以便能够阅读至少有关基础数学和计算的文本,执行Web搜索并从所阅读的材料中得出基本结论,并能够在逻辑上约束问题带有代码示例.请成长到适当的水平(这并非难事),然后欢迎您回来.拜托,没有冒犯;我们将很高兴为您提供帮助,并祝您一切顺利.

祝你好运.希望很快能收到您的回音.

—SA

Let me remind you: this is forum for software developers, engineers or students. Asking questions also assumes some prerequisites: an inquirer is supposed to be educated enough to be able to read texts on at least elementary mathematics and computing, perform Web search and make elementary conclusions from the material read, and to be able to logically bind the question with code sample posted. Please, grow to appropriate level (this is not so hard to do) and welcome back. Please, no offense; we would always be glad to help and wish you only the best.

Good luck. Hope to hear from you soon.

—SA


这篇关于如何编写源代码以查找“圆环区域"并与GUI一起显示?在java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆