我有一个文本文件,我想包含在我的Android应用程序中,它不是一个字符串文件,它是一个标准的文本文件.它包含定义在板上绘制的"地图"特征的数据.该文件不是XML文件,所以我不确定我应该把它放在哪里,或者这对于android来说这不是一个好的文件结构?你想这样做吗?如果你在那个目录下,你想把它们放在哪个目录下?你怎么想访问该文件?我知道如何使用FileInputStreams和FileOutputStreams我只需要知道如何访问该文件.欢迎并赞赏所有相关答案!
我将JPanel子类化为覆盖paintComponent(Graphics),我想在jframe中将图像绘制到jpanel上.
但是在我改变jframe的大小之前,我的图像还没有显示出来.这是我的代码:
public class ImagePanel extends JPanel{
public void setImage(BufferedImage bi)
{
image = bi;
revalidate();
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image != null)
{
g.drawImage(image, 0, 0, this);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在为比赛做一些练习问题,我一直在研究这个算法.如果你想在这里阅读整个问题,但我会给你一个简短的解释,因为这是一个很长的问题.
您必须通过将ID号插入校验和来验证ID号.在将ID插入算法之前,需要将ID转换为base-10.身份证号码以字母开头:
Z = 0,Y = 1,X = 2,W = 3,V = 4
我从这些字母到base-10的转换没有问题,我的转换代码很好,所以我会告诉你问题的下一部分:
获得base-10 ID号后,需要将其插入以下算法:
注意:每个ID号必须是8位数字,0表示在一个不至少8位数的数字之前.
checksum = F(0, d0) X F(1, d1) X F(2, d2) ...
Run Code Online (Sandbox Code Playgroud)
所以简化:
checksum = F(n, dn) X F(n+1, dn) ...
where n is the index of the digit
Run Code Online (Sandbox Code Playgroud)
这里最重要的是X不是操作*(乘法).X是后来定义的自己的操作.
注意:最重要的数字似乎是,d7
但我不确定,问题不是很清楚.
以下是f(n1,n2),g(n)和运算符X的定义:
f(n1,n2)=
g(n)=
算子X:
我假设mod
和%
我的代码一样,我不确定是否还有其他mod
我不熟悉的操作.
这就是我决定要解决问题的方法:
int[8]
int[8]
通过的每个数字f(n, dn)
这是我的算法函数.如果它们在某处混淆,我可以评论它们,但它们确实遵循上面列出的算法.
/*
* This will …
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,当一个"游戏"统计,它启动几个不同的线程.我开始这样的线程:
Thread thread = new Thread(new Runnable()
{
public void run()
{
//...
}
});
thread.setName("killMeAtEnd");
thread.start();
Run Code Online (Sandbox Code Playgroud)
稍后当游戏结束时,我在游戏内部有一个dispose()方法,它对所有正在运行的线程进行排序,并结束所有名为"killMeAtEnd"的线程.我的问题是,这是一个好习惯吗?我的目的是保持我的应用程序快速运行并且杂乱无章,根据我的经验,留下"悬挂"的线程往往会降低手机的速度,直到应用程序终止.有一个更好的方法吗?这甚至值得打扰吗?
编辑:
dispose()
如果有人有兴趣,这是我的.此代码在Game类中.
public void dispose()
{
Thread threads[] = (Thread[])Thread.getAllStackTraces().keySet().toArray();
for(int x=0;x<threads.length;x++)
{
Thread thread = threads[x];
if(thread.getName().equalsIgnoreCase(KILL))
{
try
{
thread.interrupt();
}catch(Exception e){Log.e(Viewer.GAME,Log.getStackTraceString(e));}
thread = null;
}
}
}
public static final String KILL = "endOnDispose";
Run Code Online (Sandbox Code Playgroud) 我在JScrollPane中有一个JPanel,而JPanel在函数中使用了箭头键.令人讨厌的是,当按下箭头键时,JScrollPane会滚动.如何使它在按下箭头键时不滚动JScrollPane?
我有以下代码,我想知道是否有办法使用开关块而不是一堆if/else语句.我知道Java从Java 1.7开始支持交换机块中的字符串,但我仍在使用Java 1.6:
} else if (typeName.equals("Boolean")) {
return new SwitchInputType<Boolean>(new Boolean((String) memberValue));
} else if (typeName.equals("Double")) {
return new SwitchInputType<Double>(new Double((String) memberValue));
} else if (typeName.equals("Int32"))
Run Code Online (Sandbox Code Playgroud) 在关闭此文件之前,为了复制以下帖子之一,Java改变了Java 1.8中可运行applet的要求.这些要求使得无法运行未由可信证书签名的applet.解决这个问题的唯一方法是将网站添加到例外列表中,这对我来说不是很奇怪.
相关但过时的帖子:
我和我的"公司"创造了一个我们想要放在我们网站上的游戏.我们将java应用程序转换为Applet.applet完美地在appletViewer中运行,但它不会在网页中运行.以下是我们使用的清单:
Manifest-Version: 1.0
Application-Name: Battle-Ship
Permissions: sandbox
Created-By: Chetter-Games
// empty line
Run Code Online (Sandbox Code Playgroud)
jar文件使用我们自己生成的密钥库进行签名(它不是来自可靠的证书分发者).这是jarsigner的输出:
Enter Passphrase for keystore:
jar signed.
Warning:
No -tsa or -tsacert is provided and this jar is not timestamped. Without a
timestamp, users may not be able to validate this jar after the signer
certificate's expiration date (2015-12-09) or after any future revocation date.
Run Code Online (Sandbox Code Playgroud)
我很确定这个错误可以忽略不计.这可能会在以后引起问题,但我们只是想立即启动并运行.
这是包含嵌入式applet的页面的html:
<html>
<body>
<applet code='battleShip.WindowApplet'
archive='signed-BattleShip.jar'
width=500 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试按下按钮时动态创建一个组件,然后将其添加到当前父级.我不确定我在这里做错了什么,
我有这个简单的布局:
import QtQuick 2.0
import Ubuntu.Components 0.1
import "components"
import "componentCreation.js" as MyScript
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "com.ubuntu.developer..SpritePractice"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
width: units.gu(100)
height: units.gu(75)
Page {
title: i18n.tr("Simple")
Column …
Run Code Online (Sandbox Code Playgroud) 我想制作一个始终具有焦点的JFrame,并且在关闭之前不能失去焦点,我已经将它设置为始终在顶部并且我尝试了这段代码:
import java.awt.event.*;
import javax.swing.*;
public class Viewer extends JFrame WindowFocusListener
{
public Viewer()
{
addWindowFocusListener(this);
setAlwaysOnTop(true);
this.setFocusable(true);
this.setFocusableWindowState(true);
panel = new JPanel();
setSize(WIDTH,HEIGHT);
setLocation(X,Y);
setResizable(false);
setVisible(true);
}
public void windowGainedFocus(WindowEvent e){}
public void windowLostFocus(WindowEvent e)
{
toFront();
requestFocusInWindow();
System.out.println("focus lost");
}
private JPanel panel;
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
private static final int X = 100;
private static final int Y = 100;
public static void main(String args[]){new Viewer();}
} …
Run Code Online (Sandbox Code Playgroud) 在Android中,如果不将所有UI更改放在UI线程上,则会导致巨大的问题.在Swing中这么重要吗?在Android编程之前,我从未使用过回忆UIThread.您是否想在Swing中的UI线程上进行UI更改?