我希望JLabelitem3位于底部JPanel,因为有时它出现在我在窗口中的2d数组的顶部.我试着用 item3.setVerticalAlignment(JLabel.BOTTOM).方法,但它没有奏效.有什么建议?
public class Sokoban extends JPanel {
private Contents[][] field;
private Rectangle2D.Double r1;
private static final Color[] colours = {
Color.BLACK, Color.RED, Color.GREEN, Color.CYAN, Color.MAGENTA, Color.BLUE, Color.YELLOW
};
private LevelReader lr = new LevelReader();
private int currentLevel;
private Contents [][] levelData;
private int countMoves = 1;
JLabel item3 = new JLabel("ccc");
long time1;
public Sokoban(){
lr.readLevels("m1.txt");
this.setPreferredSize(new Dimension(900,500));
this.setFocusable(true);
this.requestFocus();
this.addKeyListener(new MyKeyListener());
initLevel(0);
this.add(item3);
item3.setVerticalAlignment(JLabel.BOTTOM);
}
public static void main (String[] args) {
JFrame …Run Code Online (Sandbox Code Playgroud) 我只是想创建一个简短的java程序来向用户请求一个int,然后将3添加到该int并显示它.出于某种原因,我得到的语法都错了.
import java.util.Scanner;
public class test {
public int attempt (int b) {
return 3+entry;
}
int r = attempt(entry);
public static void main (String[] args){
Scanner keyboard = new Scanner(System.in);
System.out.println ("Enter single digit int ");
int entry = keyboard.nextInt();
System.out.println("Your number is " + entry);
System.out.println("Your number is " );
System.out.println("The final result is " + r);
}
}
Run Code Online (Sandbox Code Playgroud)