- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
package greed;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.Scanner;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
public class Greed extends JPanel {
public static BufferedImage slot1, slot2, slot3, slot4, slot5;
public static int diceOne, diceTwo, diceThree, diceFour, diceFive = 0;
public static String diceLoc1 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static String diceLoc2 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static String diceLoc3 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static String diceLoc4 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static String diceLoc5 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static String diceLoc6 = "C:/Users/Kameron/Downloads/Dice/DiceBlankResize.jpg";
public static boolean canRerollDiceOne = true;
public static boolean canRerollDiceTwo = true;
public static boolean canRerollDiceThree = true;
public static boolean canRerollDiceFour = true;
public static boolean canRerollDiceFive = true;
public static double playerOneScore = 0;
public static double playerTwoScore = 0;
public static double playerThreeScore = 0;
public static double playerFourScore = 0;
public static double OneValue = 100;
public static double TwoValue = 0;
public static double ThreeValue = 0;
public static double FourValue = 0;
public static double FiveValue = 50;
public static double SixValue = 0;
public static int playerTurn = 0;
/*
public static int diceOneRoll;
public static int diceTwoRoll;
public static int diceThreeRoll;
public static int diceFourRoll;
public static int diceFiveRoll;
*/
public static String choiceReroll = "";
// The menus
public static String menu = "";
public static int rerollSel;
public static byte[] contents;
public static int pointer = 0;
public static JFrame f = new JFrame("Greed");
public static JMenuBar mb = new JMenuBar();
public static JTextArea jTextArea1 = new JTextArea();
public static JTextArea jTextArea2 = new JTextArea();
public static JScrollPane jScrollPane1 = new JScrollPane(jTextArea1);
public static JPanel jPanel1 = new JPanel();
public static JLabel diceLab1 = new JLabel("Dice 1");
public static JLabel diceLab2 = new JLabel("Dice 2");
public static JLabel diceLab3 = new JLabel("Dice 3");
public static JLabel diceLab4 = new JLabel("Dice 4");
public static JLabel diceLab5 = new JLabel("Dice 5");
public static Toolkit tk = Toolkit.getDefaultToolkit();
public static int xSize = ((int) tk.getScreenSize().getWidth());
public static int ySize = 500;
public static int height = ((int) tk.getScreenSize().getHeight());
public static int width = ((int) tk.getScreenSize().getWidth());
public static int slot1x, slot2x, slot3x, slot4x, slot5x;
public static int sloty = 550;
public static int x1Img1 = 250;
public static int x2Img1 = 375;
public static int x1Img2 = 495;
public static int x2Img2 = 620;
public static int x1Img3 = 740;
public static int x2Img3 = 865;
public static int x1Img4 = 985;
public static int x2Img4 = 1110;
public static int x1Img5 = 1230;
public static int x2Img5 = 1355;
public static int yLine = 550;
public static int yImgSize = 200;
public static void Greed() {
f.setJMenuBar(mb);
//jScrollPane1.setBounds(10,60,780,500);
//jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
}
public void setDie1(BufferedImage slot1) {
Greed.slot1 = slot1;
}
public void setDie2(BufferedImage slot2) {
this.slot2 = slot2;
}
public void setDie3(BufferedImage slot3) {
this.slot3 = slot3;
}
public void setDie4(BufferedImage slot4) {
this.slot4 = slot4;
}
public void setDie5(BufferedImage slot5) {
this.slot5 = slot5;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//g.drawRect(250, 550, 120, 120);
//g.drawRect(495, 550, 120, 120);
//g.drawRect(740, 550, 120, 120);
//g.drawRect(985, 550, 120, 120);
//g.drawRect(1230, 550, 120, 120);
g.drawImage(slot1, 250, sloty, this);
g.drawImage(slot2, 495, sloty, this);
g.drawImage(slot3, 740, sloty, this);
g.drawImage(slot4, 985, sloty, this);
g.drawImage(slot5, 1230, sloty, this);
}
public static void main(String[] args) throws IOException {
Greed gui = new Greed();
gui.launchFrame();
//run();
Container contentPane = f.getContentPane();
contentPane.add(new Greed());
Scanner is = new Scanner(System.in);
System.out.println("Welcome to Greed...");
do {
System.out.println("Would you like to play? (yes/no)");
menu = is.next();
switch (menu) {
case "yes":
diceOne = 0;
diceTwo = 0;
diceThree = 0;
diceFour = 0;
diceFive = 0;
Game();
break;
case "no":
System.out.println("Goodbye...");
System.exit(0);
break;
default:
invalidInput();
break;
}
} while (!"yes".equals(menu) || !"no".equals(menu));
}
public static void Game() throws IOException {
rollDiceOne();
rollDiceTwo();
rollDiceThree();
rollDiceFour();
rollDiceFive();
displayDice();
displayDiceValues();
f.repaint();
System.out.println(diceLoc1);
choiceRerollDice();
}
public static void choiceRerollDice() {
Scanner is = new Scanner(System.in);
do {
if (!canRerollDiceOne && !canRerollDiceTwo && !canRerollDiceThree && !canRerollDiceFour && !canRerollDiceFive) {
System.out.println("Sorry, but you may not reroll any more dice...");
displayDiceValues();
System.exit(0);
}
else {
System.out.println("Would you like to reroll any (more) dice? (yes/no)");
choiceReroll = is.next();
switch (choiceReroll) {
case "yes":
rerollDice();
break;
case "no":
//endTurn();
displayDice();
displayDiceValues();
f.repaint();
System.out.println("Thank you for playing!");
System.out.println("Goodbye!");
System.exit(0);
default:
invalidInput();
}
}
} while (!"yes".equals(choiceReroll) || !"no".equals(choiceReroll));
}
public static void rerollDice() {
Scanner is = new Scanner(System.in);
System.out.println("Which dice would you like to reroll? (1-5)");
rerollSel = is.nextInt();
switch (rerollSel) {
case 1:
if (canRerollDiceOne) {
diceOne = 0;
rollDiceOne();
canRerollDiceOne = false;
}
else {
System.out.println("Sorry, but you may not reroll this dice!");
choiceRerollDice();
}
break;
case 2:
if (canRerollDiceTwo) {
diceTwo = 0;
rollDiceTwo();
canRerollDiceTwo = false;
}
else {
System.out.println("Sorry, but you may not reroll this dice!");
choiceRerollDice();
}
break;
case 3:
if (canRerollDiceThree) {
diceThree = 0;
rollDiceThree();
canRerollDiceThree = false;
}
else {
System.out.println("Sorry, but you may not reroll this dice!");
choiceRerollDice();
}
break;
case 4:
if (canRerollDiceFour) {
diceFour = 0;
rollDiceFour();
canRerollDiceFour = false;
}
else {
System.out.println("Sorry, but you may not reroll this dice!");
choiceRerollDice();
}
break;
case 5:
if (canRerollDiceFive) {
diceFive = 0;
rollDiceFive();
canRerollDiceFive = false;
}
else {
System.out.println("Sorry, but you may not reroll this dice!");
choiceRerollDice();
}
break;
default:
System.out.println("Invalid dice number...");
System.out.println("Please enter a dice 1-5...");
rerollDice();
break;
}
}
public static void invalidInput() {
System.out.println("Invalid input...");
System.out.println("Please enter either 'yes' or 'no'...");
}
public static void playerTurn() {
switch (playerTurn) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
}
}
public static void rollDiceOne() {
diceOne = 1 + (int)(Math.random()*6);
}
public static void rollDiceTwo() {
diceTwo = 1 + (int)(Math.random()*6);
}
public static void rollDiceThree() {
diceThree = 1 + (int)(Math.random()*6);
}
public static void rollDiceFour() {
diceFour = 1 + (int)(Math.random()*6);
}
public static void rollDiceFive() {
diceFive = 1 + (int)(Math.random()*6);
}
public static void resetDiceOne() {
diceOne = 0;
}
public static void resetDiceTwo() {
diceTwo = 0;
}
public static void resetDiceThree() {
diceThree = 0;
}
public static void resetDiceFour() {
diceFour = 0;
}
public static void resetDiceFive() {
diceFive = 0;
}
public static void displayDice() {
switch (diceOne) {
case 1:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice1Resize.jpg";
break;
case 2:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice2Resize.jpg";
break;
case 3:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice3Resize.jpg";
break;
case 4:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice4Resize.jpg";
break;
case 5:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice5Resize.jpg";
break;
case 6:
diceLoc1 = "C:/Users/Kameron/Downloads/Dice/Dice6Resize.jpg";
break;
}
switch (diceTwo) {
case 1:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice1Resize.jpg";
break;
case 2:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice2Resize.jpg";
break;
case 3:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice3Resize.jpg";
break;
case 4:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice4Resize.jpg";
break;
case 5:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice5Resize.jpg";
break;
case 6:
diceLoc2 = "C:/Users/Kameron/Downloads/Dice/Dice6Resize.jpg";
break;
}
switch (diceThree) {
case 1:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice1Resize.jpg";
break;
case 2:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice2Resize.jpg";
break;
case 3:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice3Resize.jpg";
break;
case 4:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice4Resize.jpg";
break;
case 5:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice5Resize.jpg";
break;
case 6:
diceLoc3 = "C:/Users/Kameron/Downloads/Dice/Dice6Resize.jpg";
break;
}
switch (diceFour) {
case 1:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice1Resize.jpg";
break;
case 2:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice2Resize.jpg";
break;
case 3:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice3Resize.jpg";
break;
case 4:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice4Resize.jpg";
break;
case 5:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice5Resize.jpg";
break;
case 6:
diceLoc4 = "C:/Users/Kameron/Downloads/Dice/Dice6Resize.jpg";
break;
}
switch (diceFive) {
case 1:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice1Resize.jpg";
break;
case 2:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice2Resize.jpg";
break;
case 3:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice3Resize.jpg";
break;
case 4:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice4Resize.jpg";
break;
case 5:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice5Resize.jpg";
break;
case 6:
diceLoc5 = "C:/Users/Kameron/Downloads/Dice/Dice6Resize.jpg";
break;
}
}
public static void displayDiceValues() {
System.out.println("Dice One = " + diceOne);
System.out.println("Dice Two = " + diceTwo);
System.out.println("Dice Three = " + diceThree);
System.out.println("Dice Four = " + diceFour);
System.out.println("Dice Five = " + diceFive);
}
public static void diceValuable() {
}
public static void scoreDicePlayerOne() {
switch (diceOne) {
case 1:
}
}
public static void scoreDicePlayerTwo() {
switch (diceOne) {
case 1:
}
}
public static void scoreDicePlayerThree() {
switch (diceOne) {
case 1:
}
}
public static void scoreDicePlayerFour() {
switch (diceOne) {
case 1:
}
}
public static void calculateScorePlayer1() {
}
public static void calculateScorePlayer2() {
}
public static void calculateScorePlayer3() {
}
public static void calculateScorePlayer4() {
}
public void launchFrame() throws IOException {
// Display Frame
BufferedImage slot1 = ImageIO.read(new File(diceLoc1));
BufferedImage slot2 = ImageIO.read(new File(diceLoc2));
BufferedImage slot3 = ImageIO.read(new File(diceLoc3));
BufferedImage slot4 = ImageIO.read(new File(diceLoc4));
BufferedImage slot5 = ImageIO.read(new File(diceLoc5));
setDie1 contentPane1 = new setDie1(slot1);
setDie2 contentPane2 = new setDie2(slot2);
setDie3 contentPane3 = new setDie3(slot3);
setDie4 contentPane4 = new setDie4(slot4);
setDie5 contentPane5 = new setDie5(slot5);
contentPane1.setOpaque(false);
contentPane2.setOpaque(false);
contentPane3.setOpaque(false);
contentPane4.setOpaque(false);
contentPane5.setOpaque(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack(); //Adjusts panel to components for display
f.setVisible(true);
f.add(jTextArea1);
//f.add(jTextArea2);
//f.add(jPanel1);
//f.add(jScrollPane1);
f.add(diceLab1);
f.add(diceLab2);
f.add(diceLab3);
f.add(diceLab4);
f.add(diceLab5);
f.add(contentPane1);
f.add(contentPane2);
f.add(contentPane3);
f.add(contentPane4);
f.add(contentPane5);
f.setSize(750, 500);
jTextArea1.setSize(xSize, ySize);
//jTextArea2.setSize(750, 50);
//jPanel1.setSize(xSize, 120);
jTextArea1.setLocation(0, 0);
//jTextArea2.setLocation(0, 500);
//jPanel1.setLocation(0, 500);
diceLab1.setLocation(292, 515);
diceLab2.setLocation(537, 515);
diceLab3.setLocation(782, 515);
diceLab4.setLocation(1027, 515);
diceLab5.setLocation(1272, 515);
contentPane1.setLocation(292, 515);
contentPane2.setLocation(537, 515);
contentPane3.setLocation(782, 515);
contentPane4.setLocation(1027, 515);
contentPane5.setLocation(1272, 515);
diceLab1.setSize(36, 50);
diceLab2.setSize(36, 50);
diceLab3.setSize(36, 50);
diceLab4.setSize(36, 50);
diceLab5.setSize(36, 50);
contentPane1.setSize(36, 50);
contentPane2.setSize(36, 50);
contentPane3.setSize(36, 50);
contentPane4.setSize(36, 50);
contentPane5.setSize(36, 50);
//jPanel1.setBackground(Color.red);
//jTextArea2.setBackground(Color.blue);
Greed.this.repaint();
System.out.println(ySize);
System.out.println("Screen Resolution is: " + height + " x " + width);
}
public static void run()
{
redirectSystemStreams();
}
//The following codes set where the text get redirected. In this case, jTextArea1
private static void updateTextArea(final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jTextArea1.append(text);
}
});
}
//Followings are The Methods that do the Redirect, you can simply Ignore them.
private static void redirectSystemStreams() {
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
updateTextArea(String.valueOf((char) b));
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
updateTextArea(new String(b, off, len));
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};
System.setOut(new PrintStream(out, true));
System.setErr(new PrintStream(out, true));
}
}
class setDie1 extends JPanel {
public setDie1 (BufferedImage slot1) {
Greed.slot1 = slot1;
}
}
class setDie2 extends JPanel {
public setDie2 (BufferedImage slot2) {
Greed.slot2 = slot2;
}
}
class setDie3 extends JPanel {
public setDie3 (BufferedImage slot3) {
Greed.slot3 = slot3;
}
}
class setDie4 extends JPanel {
public setDie4 (BufferedImage slot4) {
Greed.slot4 = slot4;
}
}
class setDie5 extends JPanel {
public setDie5 (BufferedImage slot5) {
Greed.slot5 = slot5;
}
}
这是我的代码当我调用 f.repaint(); 时重新绘制我的框架,它不会更新任何内容。当我尝试调用 Greed.repaint(); 时它告诉我不能从静态上下文中引用非静态变量。我该怎么办?我已经在谷歌上搜索了几个小时,我什至尝试过referenceObject.methodName();但这种格式对我来说不起作用。我已经知道我的代码可能有点困惑,因为我仍在掌握 java 并且我知道我对静态很烂......但有什么想法吗?
提前致谢,卡梅伦
最佳答案
我会首先更仔细、更长时间地审视......
关于java - 如何重新绘制 JFrame 以更新变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057436/
我查看了网站上的一些问题,但还没有完全弄清楚我做错了什么。我有一些这样的代码: var mongoose = require('mongoose'), db = mongoose.connect('m
基本上,根据 this bl.ocks,我试图在开始新序列之前让所有 block 都变为 0。我认为我需要的是以下顺序: 更新为0 退出到0 更新随机数 输入新号码 我尝试通过添加以下代码块来遵循上述
我试图通过使用随机数在循环中设置 JSlider 位置来模拟“赛马”的投注结果。我的问题是,当然,我无法在线程执行时更新 GUI,因此我的 JSlider 似乎没有在竞赛,它们从头到尾都在运行。我尝试
该功能非常简单: 变量:$table是正在更新的表$fields 是表中的字段,$values 从帖子生成并放入 $values 数组中而$where是表的索引字段的id值$indxfldnm 是索引
让我们想象一个环境:有一个数据库客户端和一个数据库服务器。数据库客户端可以是 Java 程序或其他程序等;数据库服务器可以是mysql、oracle等。 需求是在数据库服务器上的一个表中插入大量记录。
在我当前的应用程序中,我正在制作一个菜单结构,它可以递归地创建自己的子菜单。然而,由于这个原因,我发现很难也允许某种重新排序方法。大多数应用程序可能只是通过“排序”列进行排序,但是在这种情况下,尽管这
Provisioning Profile 有 key , key 链依赖于它。我想知道 key 什么时候会改变。 Key will change after renew Provisioning Pr
截至目前,我在\server\publications.js 中有我的 MongoDB“选择”,例如: Meteor.publish("jobLocations", function () { r
我读到 UI 应该始终在主线程上更新。但是,当谈到实现这些更新的首选方法时,我有点困惑。 我有各种函数可以执行一些条件检查,然后使用结果来确定如何更新 UI。我的问题是整个函数应该在主线程上运行吗?应
我在代理后面,我无法构建 Docker 镜像。 我试过 FROM ubuntu , FROM centos和 FROM alpine ,但是 apt-get update/yum update/apk
我构建了一个 Java 应用程序,它向外部授权客户端公开网络服务。 Web 服务使用带有证书身份验证的 WS-security。基本上我们充当自定义证书颁发机构 - 我们在我们的服务器上维护一个 ja
因此,我有时会在上传新版本时使用 app_offline.htm 使应用程序离线。 但是,当我上传较大的 dll 时,我收到黄色错误屏幕,指出无法加载 dll。 这似乎与我对 app_offline.
我刚刚下载了 VS Apache Cordova Tools Update 5,但遇到了 Node 和 NPM 的问题。我使用默认的空白 cordova 项目进行测试。 版本 如果我在 VS 项目中对
所以我有一个使用传单库实例化的 map 对象。 map 实例在单独的模板中创建并以这种方式路由:- var app = angular.module('myApp', ['ui', 'ngResour
我使用较早的 Java 6 u 3 获得的帧速率是新版本的两倍。很奇怪。谁能解释一下? 在 Core 2 Duo 1.83ghz 上,集成视频(仅使用一个内核)- 1500(较旧的 java)与 70
我正在使用 angular 1.2 ng-repeat 创建的 div 也包含 ng-click 点击时 ng-click 更新 $scope $scope 中的变化反射(reflect)在使用 $a
这些方法有什么区别 public final void moveCamera(CameraUpdate更新)和public final void animateCamera (CameraUpdate
我尝试了另一篇文章中某人评论中关于如何将树更改为列表的建议。但是,我在某处(或某物)有未声明的变量,所以我列表中的值是 [_G667, _G673, _G679],而不是 [5, 2, 6],这是正确
实现以下场景的最佳方法是什么? 我需要从java应用程序调用/查询包含数百万条记录的数据库表。然后,对于表中的每条记录,我的应用程序应该调用第三方 API 并获取状态字段作为响应。然后我的应用程序应该
只是在编写一些与 java 图形相关的代码,这是我今天的讲座中的非常简单的示例。不管怎样,互联网似乎说更新不会被系统触发器调用,例如调整框架大小等。在这个例子中,更新是由这样的触发器调用的(因此当我只
我是一名优秀的程序员,十分优秀!