小编How*_*can的帖子

在Java中显示弹出消息窗口?

我读到了JDialogs和JOptionPane消息,但我仍然无法让它工作.我有一个扩展JFrame的GUI类.我想要做的就是在程序开头弹出一个弹出窗口,告诉用户一些事情.在我的主要内容中,我创建了以下gui:

GUI g = new GUI();
Run Code Online (Sandbox Code Playgroud)

在那之后我就是要显示窗口.我在main方法中尝试了以下内容:

JOptionPane.showMessageDialog(g, "work?");
JOptionPane.showMessageDialog(frame, "work?"); //(frame was used in documentation example so I tried it)
Run Code Online (Sandbox Code Playgroud)

我还尝试使用以下内容将弹出窗口添加到GUI类中

JOptionPane.showMessageDialog(this, "work?"); //(I'm not exactly sure what the Frame Owner parameter is supposed to be, unless I'm confusing this with JDialog.)
Run Code Online (Sandbox Code Playgroud)

在任何情况下,我将如何使这个窗口出现?我尝试编译的每一个方法都没有发生.

public class GUI extends JFrame implements ActionListener{
     private Container background;
     private static buttons etc...
     private static JLabel disp,edisp;
     private static JTextArea info;
     //setting up the GUI for my program, adding action listeners, I can post more …
Run Code Online (Sandbox Code Playgroud)

java swing jdialog joptionpane

2
推荐指数
1
解决办法
2万
查看次数

类之间的修复方法冲突?

在我的Character类中,我有一个简单的方法getHealth:

public int getHealth(){
    return health;
}
Run Code Online (Sandbox Code Playgroud)

在另一个课程中,我有以下方法

public static void playerCombat(ArrayList attacking, ArrayList targets){
Run Code Online (Sandbox Code Playgroud)

此方法采用2个3个字符的数组.

我也有条件,它只能在玩家健康状况> 0时运行.

    public static void playerCombat(ArrayList attacking, ArrayList targets){
         While(attacking.get(0).getHealth() > 0){
               blablabla
         }
    }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Driver.java:13: cannot find symbol
symbol  : method getHealth()
location: class java.lang.Object
Run Code Online (Sandbox Code Playgroud)

但是在下面的Main方法中我使用getHealth()方法,它工作正常.我如何解决这个/为什么它在main方法中工作但不是这个?

java arraylist

1
推荐指数
1
解决办法
61
查看次数

使用字典制作matplotlib图?

如果我在字符串中有单词及其频率的字典,例如:

{'hello': 3, 'how': 4, 'yes': 10, 'you': 11, 'days': 10, 'are': 20, 'ago': 11}
Run Code Online (Sandbox Code Playgroud)

我如何使用matplotlib制作一个条形图?我发现之前的问题有一个看似很好的解决方案,但它对我不起作用(python:使用matplotlib使用字典绘制条形图)

我跑的时候

plt.bar(range(len(d)), d.values(), align="center")
plt.xticks(range(len(d)), d.keys())
Run Code Online (Sandbox Code Playgroud)

我收到了错误

TypeError: 'dict_keys' object does not support indexing
Run Code Online (Sandbox Code Playgroud)

我真的没看到我在哪里索引我的字典.这可能是因为在我得到代码的问题中,x值也是数字?我不确定.

python dictionary matplotlib

1
推荐指数
1
解决办法
1万
查看次数

JAVA:缺少退货声明

我现在对此代码的主要关注是缺少返回语句.

public class stringstuff{

    //using charAt    
    public static String ReverseF(String n){
        String finalstring = "";
        int len = n.length();
        for (int i = 0; (i < n.length()); i++){
            finalstring += (n.charAt(len - i - 1));
        }
        System.out.println(finalstring);
    }

    public static void main(String[]args){
        ReverseF("Hello");
    }
}
Run Code Online (Sandbox Code Playgroud)

使用此代码我只得到错误:

stringstuff.java:11: missing return statement
}
^
1 error
Run Code Online (Sandbox Code Playgroud)

如果我切换System.out.println返回,我没有得到任何错误,但我也没有得到ReverseF的答案("你好");

java javac

0
推荐指数
1
解决办法
1万
查看次数

JAVA:帮助修复递归函数

我必须使用递归来解决这个问题,我设法让它很快就能使用循环,但是我有点困惑于此.我目前的代码是

public static String ReverseR(String n){
    String finalstring="";
    int i = 0;
    int len = n.length();
    while (i < len) {
        finalstring += (n.charAt(len -  1));
        ReverseR(n.substring(0, len - 1));
        i++;
    }
    return finalstring;
}
Run Code Online (Sandbox Code Playgroud)

当我输入任何字符串时,结果字符串的长度是正确的,但只使用最后一个字母.例:ReverseR("你好")= ooooo有什么想法吗?

java recursion

0
推荐指数
1
解决办法
157
查看次数