我想知道如何制作一个可以用来打开东西的java程序.例如:notepad ++,win zip ....我是否已将jar转换为.exe第一个?此外,选择的文件是否传入String[] args?
顺便说一句,我知道它适用于cmd,但那不是我要问的.
我有一个问题,我有一个包含值C:\ Users\Ewen\AppData\Roaming\MyProgram\Test.txt的String,我想删除C:\ Users\Ewen\AppData\Roaming\MyProgram \所以只留下测试.所以问题是,如何删除字符串的任何部分.
谢谢你的时间!:)
我有一个字符串,其中有几个单词用空格分隔,例如"firstword second third"和一个ArrayList.我想将字符串拆分成几个部分,并将'piece'字符串添加到ArrayList中.
例如,"firstword second third"可以拆分为三个单独的字符串,因此ArrayList将有3个元素; "1 2 3 4"可以分成4个字符串,在ArrayList的4个元素中.请参阅以下代码:
public void separateAndAdd(String notseparated) {
for(int i=0;i<canBeSepartedinto(notseparated);i++{
//what should i put here in order to split the string via spaces?
thearray.add(separatedstring);
}
}
public int canBeSeparatedinto(String string)
//what do i put here to find out the amount of spaces inside the string?
return ....
}
Run Code Online (Sandbox Code Playgroud)
如果你不理解我的意思,请发表评论或者我应该在这篇文章中修正一些错误.谢谢你的时间!
继承人我想做的事情,其中一个类是包含所有JButtons的JFrame,我想要另一个类来监听在JFrame类上进行的操作.请参阅以下代码:
public class Frame extends JFrame{
//all the jcomponents in here
}
public class listener implements ActionListener{
//listen to the actions made by the Frame class
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.
我需要使用Strings而不是int来创建一个int数组.EX:int["number2"] = 0; instead of int[2] = 0;
有谁知道如何做到这一点?
谢谢你的时间.
我创建了一个扩展a JFrame并JPanel在其中添加内部的类,但该paintComponents()方法不会在其上绘制任何内容JPanel.继承人的代码paintComponents(),我选择使用双重图像缓冲.
public void paintComponents(Graphics graphics) {
panel.paintComponents(graphics);
bufferedImage = createImage(sizeX, sizeY);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
for (ImageData myImage : imageData) {
g.drawImage(myImage.getImage(), myImage.getX(), myImage.getY(), null);
}
graphics.drawImage(bufferedImage, 0, 0, null);
}
Run Code Online (Sandbox Code Playgroud)
这有什么不对吗?顺便说一句,我尝试过paint()它但是我认为这不是正确的方法.
谢谢你的时间.:)
我正在编写一个编程语言,我需要将一个对象(如javascript中的var)转换为它应该的变量类型.例如:
if(object == variabletypes.string)
{
//convert object to string
}
else if(object ==variabletypes.int)
{
//convert to integer
}
Run Code Online (Sandbox Code Playgroud)
感谢您的时间,任何帮助将不胜感激.
我正在用Java创建一个3D渲染器,它当前可以使用点和线渲染立方体的线框并旋转立方体,问题是,Z应该是什么?什么应该设置为Z?我猜测立方体的大小应该设置为Z?
谢谢你的时间!任何答案将不胜感激.
我想知道如何在屏幕上绘制jcomponent,它是否在Graphics的paintComponent()中绘制?或者它是单独绘制的.我问这个是因为jbutton在mousehover上改变颜色很奇怪,即使从不调用repaint()也是如此.
谢谢你的时间.
我不是一个非常优秀的Java程序员,我需要知道如何打印出单个文件夹中的所有文件.请参阅以下代码:
for(int i=0;i<folder.number_of_files;i++){
System.out.println(filename[i]);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间
在我的paintComponent()方法中,我有一个绘制jpanel背景的drawRect().但由于在调用paintComponent()方法之前在屏幕上绘制了jbutton,因此drawRect会阻止jbutton.有谁知道如何解决这一问题?我的猜测是在重新调用之前添加jbutton,但我不知道该怎么做?
一些代码:
public Frame(){
add(new JButton());
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawRect(0,0,screenwidth,screenheight); //paints the background with a color
//but blocks out the jbutton.
}
Run Code Online (Sandbox Code Playgroud)