我有很长的形式
20120720162145
yyyymmddhhmmss
Run Code Online (Sandbox Code Playgroud)
我必须把它转换成2012-07-20 4:21 PM形式.Java中有没有办法使用它Date?
我想运行一些unix/shell命令Java并处理输出.我用过getRuntime.exec(),但它没有为某些命令提供正确的输出ls directory_path/*.tar.gz.对于那个命令,我的程序没有给出任何输出,但它给出了错误说法No such file or directory.但是相同的命令在命令提示符下提供正确的输出.
有没有其他方法可以在Java中执行包含通配符的命令?
我有以下代码:
ArrayList<? extends IValues> valuesList
Run Code Online (Sandbox Code Playgroud)
IValues是一个interface.该列表填充implement了IValues接口的类/对象.我理解这个列表中每个对象的概念必须履行它们实现的接口所规定的合同.为什么java语言不这样做:
ArrayList<? implements IValues> valuesList
Run Code Online (Sandbox Code Playgroud)
?这对用户来说会更清楚,不是吗?
我今天一直在玩GUI,并尝试添加不同的元素,
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton1)
{
//Do Something
}
JComboBox cb = (JComboBox)e.getSource();
String petName = (String)cb.getSelectedItem();
if(petName == "Cat")
{
//Do Something
}
}
Run Code Online (Sandbox Code Playgroud)
当我点击jButton1它完成我想要它做什么,当我从组合框中选择"猫"它做我想要它做的,但只有当我点击jButton1而不是当我选择猫时它给了我以下错误
javax.swing.JButton无法强制转换为javax.swing.JComboBox
任何想法显然与comboxbox代码有关,当我从JCombobox中删除代码时,错误不会出现.
任何帮助都会很好,而不是家庭作业只是搞乱,看看我是否可以学习新东西
让我们考虑这个例子:
public class Shared {
private int attribute;
public Shared() {}
public void incrementAttribute(int i) {
attribute += i;
}
public int getAttribute() {
return attribute;
}
public static void main(String[] args) {
Shared s1 = new Shared();
Shared s2 = new Shared();
s1.incrementAttribute(1);
s2.incrementAttribute(1);
s1.getAttribute();
s2.getAttribute();
}
}
Run Code Online (Sandbox Code Playgroud)
如何1 2在调用时将此类更改为输出,getAttribute()而不是1 1
像全局变量,我尝试了final关键字,但我不能使用方法设置.
如果我有一个具有以下字符序列的键:_(some number)_1.我如何才能返回(some number).
例如,如果关键是_6654_1我只需要价值6654.让我感到困惑的问题/问题是数字可能是任何长度,就像_9332123425234_1在这种情况下我只需要9332123425234.
这是我到目前为止所尝试的:
Pattern p = Pattern.compile("_[\\d]_1");
Matcher match = p.matcher(request.getParameter("course_id"));
Run Code Online (Sandbox Code Playgroud)
但这不会涵盖中间数字可以是任何数字(不只是四位数)的情况吗?
下面你会找到一个SSCCE.
我想要输入几个整数,看看哪个是最大和最小的.
当我运行/调试它时,只有第一个整数将获得代码来显示System.out.println().....
import java.util.Scanner;
public class Comparison
{
public static void main(String[] args)
{
Scanner input = new Scanner ( System.in );
int a; //1st #
int b; //2nd #
int c; //3rd #
int d; //4th #
int e; //5th #
int large = 0; //Largest #
int small = 0; //Smallest #
System.out.print( "Enter the first integer: ");
a = input.nextInt();
System.out.print( "Enter the second integer: ");
b = input.nextInt();
System.out.print( "Enter the third integer: …Run Code Online (Sandbox Code Playgroud) 所以我们说有一个带有main方法的类SimpleGame(slick2d btw):
public static void main(String[] args) throws SlickException {
AppGameContainer app = new AppGameContainer(new SimpleGame());
Run Code Online (Sandbox Code Playgroud)
假设这个类在类字段声明中有许多初始化,它不会做很多不必要的类和字段吗?
我看到很多代码使用这个,我从来没有理解过.
我正在尝试加载属性文件.适当的文件位于应用程序的类路径中.
Properties p = new Properties();
p.load(new FileInputStream("classpath:mail.properties"));
System.out.println(p.get("hi"));
Run Code Online (Sandbox Code Playgroud)
现在我说classpath,因为另一个名为x.properties的文件在这样的xml文件中被引用
<property name="x">
<util:properties location="classpath:x.properties" />
</property>
Run Code Online (Sandbox Code Playgroud)
我将mail.properties放在与x.properties相同的文件夹中,但我的Java程序无法找到它?知道我错过了什么吗?
我正在开发一款扫雷游戏,目前已经基本完成。
唯一缺少的是获胜的检测。实现这一点的最佳方法是什么?我知道它将成为检测点击的动作侦听器的一部分,在某些时候,最后一次点击应该检测到获胜者。
谁能给我一些想法谢谢!
java ×10
class ×2
attributes ×1
combobox ×1
eclipse ×1
generics ×1
interface ×1
jbutton ×1
minesweeper ×1
properties ×1
regex ×1
share ×1
string ×1
swing ×1