所以我决定把编程作为一种爱好,现在我正在努力创建一个老虎机,并在教程的帮助下.但是,我遇到了重叠图像的问题.我使用照片编辑器创建了一个.png文件,我想要成为背景,有三个透明盒子供插槽动画师使用.
绘制背景的代码:
public class SlotMachineBackground extends JPanel
{
private ImageIcon image;
public void paintComponent (Graphics g)
{
super.paintComponent (g);
image = new ImageIcon ("/Users/Documents/slotmachine.png");
image.paintIcon (this, g, 0,0);
}
}//end class
Run Code Online (Sandbox Code Playgroud)
然后我做了插槽动画师:
public class SlotAnimator extends JPanel implements ActionListener
{
private Timer animator;
private ImageIcon imageArray []= new ImageIcon [22];
int currentFrame = 0;
int slotNumber = 1;
int box = 1;
SlotMachine m = new SlotMachine ();
String [] mP = m.returnTurn();
public SlotAnimator (int delay)
{
for (int …Run Code Online (Sandbox Code Playgroud) 我正在为一家虚拟公司设计一个登录系统,现在我所拥有的只是主要登录,需要大量的清理工作.下面是我的登录处理程序.
private class LoginButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(_uid.getText().equalsIgnoreCase("Nathan") && _pwd.getText().equals("password")) {
JOptionPane.showMessageDialog(null, "Congratulations on logging in!");
} else {
JOptionPane.showMessageDialog(null, "Error on login!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
原样,这种方法非常好,但是当我改为它时
_pwd.getPassword.equals("password")
Run Code Online (Sandbox Code Playgroud)
当一切输入正确时,它会直接指向else语句.这有什么不对?完整的程序如下.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
private static final int HEIGHT = 90;
private static final int WIDTH = 400;
JTextField _uid = new JTextField(10);
JPasswordField _pwd = new JPasswordField(10);
JButton _login = new JButton("Login");
JButton _reset = new JButton("Reset"); …Run Code Online (Sandbox Code Playgroud) 我在ButtonGroup中有几个JRadioButtons.
private ButtonGroup radioGroup= new ButtonGroup();
private JRadioButton radio1= new JRadioButton("Red");
private JRadioButton radio2= new JRadioButton("Green");
private JRadioButton radio3= new JRadioButton("Blue");
radioGroup.add(radio1);
radioGroup.add(radio2);
radioGroup.add(radio3);
Run Code Online (Sandbox Code Playgroud)
如何查看选择了哪一个?
随着System.out.println(radioGroup.getSelection())我只得到这样的事情javax.swing.JToggleButton$ToggleButtonModel@32b3714.
这是我目前的菜单:
public class DrawPolygons
{
public static void main (String[] args) throws FileNotFoundException
{
/**
* Menu - file reader option
*/
JMenuBar menuBar;
JMenu menu;
JMenuItem menuItem;
// Create the menu bar.
menuBar = new JMenuBar();
// Build the first menu.
menu = new JMenu("File");
menu.setMnemonic(KeyEvent.VK_F);
menu.getAccessibleContext().setAccessibleDescription("I have items");
menuBar.add(menu);
// a group of JMenuItems
menuItem = new JMenuItem("Load",KeyEvent.VK_T);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
menuItem.getAccessibleContext().setAccessibleDescription("Load your old polygons");
menu.add(menuItem);
menuItem = new JMenuItem("Save",KeyEvent.VK_U);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
menuItem.getAccessibleContext().setAccessibleDescription("Save the contents of your polygons");
menu.add(menuItem); …Run Code Online (Sandbox Code Playgroud) java model-view-controller swing jfilechooser actionlistener
我做了我认为是递归的一个例子.这可以接受吗?这不是一个项目或任何事情,我的教授是可怕的,所以我试着自学.
public void theCat() {
int i;
for (i = 0; i <= 50; i++) {
System.out.println(i);
if (i == 10) {
theCat();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用一个精灵表,并设置为获取每个精灵的像素int [],我只是不知道如何使用该像素int []来制作一个单独的图像.
我的代码:
i=0;
BufferedImage[] bi = new BufferedImage[];
for(y) {
for (x) {
int[] pixels = null;
Vars.TILE_SHEET_BI().getRaster().getPixels(x, y, 16, 16, pixels);
bi[i] = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
bi[i].getRaster().setPixels(0, 0, 16, 16, pixels);
i++;
}
}
Run Code Online (Sandbox Code Playgroud) 假设我通过 JNI 从 Java 调用一些 C 代码,并且在 C 代码中有一些全局数组。这些内存是如何分配和管理的?我假设它不会在 JVM 堆上。
我写这是为了回答我自己的问题,因为文档没有明确说明这一点,并且在堆栈溢出或其他任何地方都找不到它。这是将String数组从Java模块返回到React Native Component的方法(从我的个人项目中的代码简化)。
CPPConnection.java文件
public class CPPConnection extends ReactContextBaseJavaModule {
@ReactMethod
public void GetDerivedUnits(String scheme,final Promise promise){
try {
List<String> returnSet = new ArrayList<String>();
//Set first value so that there is a lead value
returnSet.add("");
returnSet.add(scheme);
returnSet.add("lb");
returnSet.add("kg");
String[] returnArray = new String[returnSet.size()];
returnArray = returnSet.toArray(returnArray);
WritableArray promiseArray=Arguments.createArray();
for(int i=0;i<returnArray.length;i++){
promiseArray.pushString(returnArray[i]);
}
promise.resolve(promiseArray);
}
catch(Exception e){
promise.reject(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Density.js文件
export default class Density extends Component{
...
constructor(props) {
super(props);
this.state = {
mass: '',
massUnits:[],
volume: '',
volumeUnits:[], …Run Code Online (Sandbox Code Playgroud) 我试图回答这个问题:
对 findIngredients 方法进行编程。该方法接受一个名为 foodInStock 的字符串和一个名为成分的字符串数组列表。该方法应返回在 foodInStock 中未找到的成分的 ArrayList。
例如,如果:
foodInStock = “tomatopotatocornturkeycarrotstuffing”
ingredients = {“potato”, “corn”, “salt”, “chicken”, “turkey”}
Run Code Online (Sandbox Code Playgroud)
返回{“盐”,“鸡”}
我尝试编写一些代码,但由于某种原因,当我在我的程序中使用上面的示例时,所有内容都被删除了。我的程序哪里出错了?
这是我的代码:
public static ArrayList<String> findIngredients(String foodInStock, ArrayList<String> ingredients){
ArrayList<String> ingredientsNotFound = new ArrayList<String>();
int i = 0;
for (; i < ingredients.size(); i++) {
for (int x = 0; x < foodInStock.length()-(ingredients.get(i).length())+1; x++) {
if (ingredients.get(i) == foodInStock.substring(x, (x + ingredients.get(i).length()))) {
ingredients.remove(i);
i = 0;
break;
}
}
}
ingredients = ingredientsNotFound;
return ingredientsNotFound;
}
Run Code Online (Sandbox Code Playgroud) 我有一个JTable,模型实例化为:
TableModel ss = new DefaultTableModel(myArray[][], myHeaderArray[]);
Run Code Online (Sandbox Code Playgroud)
生成数组的位置.但是,目前,您仍然可以编辑单元格.我怎么能阻止这个?
谢谢!
java ×10
swing ×5
arraylist ×1
arrays ×1
buttongroup ×1
c ×1
graphics ×1
jfilechooser ×1
jframe ×1
jpanel ×1
jradiobutton ×1
jtable ×1
loops ×1
passwords ×1
react-native ×1
recursion ×1
string ×1
substring ×1