我有一个类有这样的方法:
public ArrayList<Integer> myNumbers() {
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(11);
numbers.add(3);
return(numbers);
}
Run Code Online (Sandbox Code Playgroud)
我如何在另一个类中调用此方法?
我试图将JPanel放在另一个包含JTextArea和按钮的JPanel之上,我希望上层apnel是透明的.我通过制作上面板的setOpaque(false)来尝试它.但它不起作用.任何人都可以帮我解决这个问题吗?提前致谢!
public class JpanelTest extends JPanel
{
public JpanelTest()
{
super();
onInit();
}
private void onInit()
{
setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(new JTextArea(100,100),BorderLayout.CENTER);
panel.add(new JButton("submit"),BorderLayout.SOUTH);
JPanel glass = new JPanel();
glass.setOpaque(false);
add(panel,BorderLayout.CENTER);
add(glass,BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[])
{
new JpanelTest();
}
}
Run Code Online (Sandbox Code Playgroud) 我是java socket编程的新手.我已经知道java只处理Internet Domain Sockets,它将支持UDP和TCP以及Raw IP Protocols.我想知道java支持Raw Sockets而不使用任何第三方应用程序?如果有可能,任何人都可以用一个小例子来帮助我吗?任何小建议都会非常棒!
这似乎问题是重复此.但我的问题是我已经通过两种方式在JavaFX中开发了一个整数文本字段.代码如下
public class FXNDigitsField extends TextField
{
private long m_digit;
public FXNDigitsField()
{
super();
}
public FXNDigitsField(long number)
{
super();
this.m_digit = number;
onInitialization();
}
private void onInitialization()
{
setText(Long.toString(this.m_digit));
}
@Override
public void replaceText(int startIndex, int endIndex, String text)
{
if (text.matches(Constants.DIGITS_PATTERN) || text.equals(Constants.EMPTY_STRING)) {
super.replaceText(startIndex, endIndex, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches(Constants.DIGITS_PATTERN) || text.equals(Constants.EMPTY_STRING)) {
super.replaceSelection(text);
}
}
}
Run Code Online (Sandbox Code Playgroud)
第二种方法是添加一个事件Filter.
给出了代码片段.
// restrict key input to numerals.
this.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() { …Run Code Online (Sandbox Code Playgroud) 
我对java swing很新,不熟悉paint().我想在java swing中创建一个带有上面的按钮.任何人都可以帮我这样做.任何指导都将不胜感激.提前致谢
我为我的Android应用程序创建了自定义小部件,我想为它创建自定义样式.但是在类中解析它时总是返回null.通过几个链接,无法弄清楚问题是什么?有人可以帮忙吗?
我的atttr.xml是
<resources>
<declare-styleable name="Widget">
<attr name="headers" format="reference" />
<attr name="height" format="integer" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
小部件类
public Widget(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray attr = context.obtainStyledAttributes(attrs,
R.styleable.Widget);
String[] columns = (String[]) attr
.getTextArray(R.styleable.Widget_headers);
int height = attr.getInt(R.styleable.Widget_height, 0);
}
Run Code Online (Sandbox Code Playgroud)
和布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:widget="http://schemas.android.com/apk/lib/com.sample.custom"
android:id="@+id/statistics_fragment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.sample.custom.Widget
android:id="@+id/widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
widget:headers="@array/headers" >
</com.sample.custom.Widget>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Arrays.xml是
<resources>
<string-array name="headers">
<item>Header1</item>
<item>Header2</item>
<item>Header3</item>
</string-array>
</resources>
Run Code Online (Sandbox Code Playgroud) 这是我的问题:我目前有一个JTable,包含5,000到200,000多行.你知道我要去哪里.数据已经加载到内存中,这不是问题,但是我如何创建一个高效的JTable,以便它只加载可见的行,并且任何事件只对视口中可见的那些行起作用?显然,使用这么多数据滚动几乎是不可能的,因为系统需要永远重新绘制和触发事件.
基本上我认为一种解决方案是确定哪些行在视口中,然后创建一个包含这些行的新模型呢?
我目前正在使用PrimeFaces组件库开发一个网站.我想知道,在PrimeFaces中是否有用于缩放(放大和缩小)图像的内置组件?
我正在使用下面的代码在任务栏上显示JDialog,并且完全在JDK 1.6中工作.
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog((Frame)null,Dialog.ModalityType.TOOLKIT_MODAL);
d.setTitle("title");
d.setSize(300,200);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用该方法设置模态类型时,它无法正常工作
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog();
d.setTitle("title");
d.setSize(300,200);
d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
Run Code Online (Sandbox Code Playgroud)
这两个代码有什么区别?有没有办法用这个方法来解决这个问题?
我想创建一个 jar(无主类),稍后在 apache pig 中用作 UDF。
当我使用 maven 创建 jar 时,依赖的 jar 不包含在输出 jar 中。
pom 文件看起来像这样
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>AppName</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>xzloader-java-pig-udf</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.pig</groupId>
<artifactId>pig</artifactId>
<classifier>h2</classifier>
<version>0.13.0</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
但结果罐子总是抛出
NoClassDefFoundException
与 apache pig 一起运行时