我正在用Java编写GUI程序.GUI由9个标题为H的按钮组成.在运行模式下,当鼠标点击任何按钮时,该按钮应将标题更改为T.我有一个MouseListener代码注意点击.但我无法根据鼠标点击找到我需要更改该特定按钮.任何帮助表示赞赏.
以下是我的代码.
package flippingcoins;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FlippingCoins extends JFrame
{
public FlippingCoins()
{
JPanel p = new JPanel();
p.setLayout(new GridLayout(3,3,1,1));
JButton jbt1=new JButton("H");
p.add(jbt1);
JButton jbt2=new JButton("H");
p.add(jbt2);
JButton jbt3=new JButton("H");
p.add(jbt3);
JButton jbt4=new JButton("H");
p.add(jbt4);
JButton jbt5=new JButton("H");
p.add(jbt5);
JButton jbt6=new JButton("H");
p.add(jbt6);
JButton jbt7=new JButton("H");
p.add(jbt7);
JButton jbt8=new JButton("H");
p.add(jbt8);
JButton jbt9=new JButton("H");
p.add(jbt9);
add(p);
}
public static void main(String[] args) //Main program begins here.
{
FlippingCoins frame = new …Run Code Online (Sandbox Code Playgroud) 我正在使用openFileDialog和showFileDialog图标创建一个窗体.但是当我运行表单时,我看不到左上角的选项.是否有一些我需要更改为可见的属性?任何帮助将不胜感激.
我有这个下面的文件.我试图在visual studio 2010中运行它.但是它一直给我一个错误,说我需要包含头文件stdafx.h.但是这个文件在头文件列表中无处可见.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int choice();
double cylinder_volume();
double cone_volume();
double sphere_volume();
void display_result(double volume);
int main ()
{
int option;
double volume;
option=choice();
if (option==1)
{
volume=cylinder_volume();
display_result(volume);
}
else
if (option==2)
{
volume=cone_volume();
display_result(volume);
}
else
if (option==3)
{
volume=sphere_volume();
display_result(volume);
}
return 0;
}
int choice()
{
int option;
cout<<"What would you like to calculate the volume of: ";
cout<<"\nPress 1 for cylinder. ";
cout<<"\nPress 2 for cone. "; …Run Code Online (Sandbox Code Playgroud)