我用不同的JButtons制作了一个JFrame,我想从另一个类中获取一个图像.有任何想法吗?或者如何在同一个类上绘制但是在执行的操作上?因为它不允许我做任何图纸......我的编译器总是给我错误信息
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
public class red extends JFrame {
public JButton b;
public JButton b1;
public JButton b2;
public JButton b3;
public JButton b4;
public static Image p;
public static Graphics g;
public red() throws IOException {
gui1 x = new gui1();
setTitle(" ");
setSize(1200,700);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b= new JButton("click");
b1= new JButton();
b.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e0){
b1.setBounds(0, 0, 200, 200);
b.show(false);
add(x);
}
});
b.setBounds(0, 0, 100, 100); …Run Code Online (Sandbox Code Playgroud) 我正在使用制作一个简单的高分系统代码 - Codecall,但我在使用它时收到错误.导致问题的一行是在HighScoreManager()课堂内.
这是错误的代码:
public String getHighscoreString() {
String highscoreString = "";
Static int max = 10; // this line gives an error
ArrayList<Score> scores;
scores = getScores();
int i = 0;
int x = scores.size();
if (x > max) {
x = max;
}
while (i < x) {
highscoreString += (i + 1) + ".\t" + scores.get(i).getNaam() + "\t\t" + scores.get(i).getScore() + "\n";
i++;
}
return highscoreString;
}
Run Code Online (Sandbox Code Playgroud)
线路Static int max = 10; …
你好,想象我们有以下课程
Manager{
public static void doSth(){
// some logic
};
}
Run Code Online (Sandbox Code Playgroud)
如何在Kotlin中覆盖该方法?
我累了用
fun Manager.doSth(){}
Run Code Online (Sandbox Code Playgroud)
但它适用于实例,而不是静态类型。
这样做的目的是避免使用PowerMockito
import java.util.*;
public class HelloWorld{
public static void main(String []args){
static String[] str={"one","two"};
Date date =new Date();
Calendar cal = Calendar.getInstance();
String year = "2018";
String month ="4";
int day =10;
cal.set(Integer.parseInt(year),Integer.parseInt(month),day);
System.out.println(cal.get(Calendar.DAY_OF_WEEK));
// etc.
}
}
Run Code Online (Sandbox Code Playgroud)
错误信息 :
错误:非法开始表达
static String [] str = {"one","two"};
public class homework
{
public static void intPow(int a, int b)
{
Math.pow(a,b);
}
public static void main(String args[])
{
intPow();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在努力学习如何创建一个方法,但我一直在增加10个; 预期的错误.我知道这段代码不正确,但我似乎无法找到如何正确创建方法.在这种情况下,我正在尝试创建一个返回^ b的方法.
我是一个java新手,尽管到处搜索,我找不到静态实际做什么的基本定义.有人可以告诉我这是什么意思吗?另外,请说出你的答案,好像我甚至不知道java是什么,没有编程语言的例子吗?非常感谢.编辑:所以我的理解是,当你在构造函数中有一个静态变量时,
i.e. you have
class test{
static int a = 5;
public test(){
}
}
Run Code Online (Sandbox Code Playgroud)
然后
test test1 = new test();
test test2 = new test():
Run Code Online (Sandbox Code Playgroud)
,test1.a等于5,test2.a也等于5.如果你改变了test1.a = 6,test2.a也会等于6?