我有两个Jframe,其中frame1有一些文本字段,当点击frame1上的一个按钮时,我打开另一个JFrame,其中包含一个搜索框和一个包含搜索结果的JTable.
当我在JTable上单击结果行时,我希望特定值反映在frame1文本字段中.
我尝试将JFrame1的对象作为参数传递,但我对如何实现这一点并不清楚.任何帮助将受到高度赞赏.谢谢
当我调用getGraphics()时,它经常返回null,即使我设置了xxx.getGraphics(); xxx可见(谷歌搜索显示......)
但这不起作用,这使我感到沮丧,因为在C-Sharp中这很简单易行.
有没有人知道更好的方法,而不是使用getGraphics()?
假设我在C++中有一个Foo类型的对象数组:
Foo array[10];
Run Code Online (Sandbox Code Playgroud)
在Java中,我可以通过以下方式将此数组中的对象设置为null:
array[0] = null //the first one
Run Code Online (Sandbox Code Playgroud)
我怎么能用C++做到这一点?
repaint()我的Java代码中的方法有问题.我想在另一个中调用它,class但我不能,有些东西根本不起作用.我在论坛上搜索过,但没有任何东西可以帮助我.
我的主要 class:
public class Main {
public static Main main;
public static JFrame f;
public Main(){
}
public static void main(String[] args) {
main = new Main();
f = new JFrame();
Ball b = new Ball();
f.getContentPane().setBackground(Color.GRAY);
f.add(b);
f.setSize(500, 500);
f.setLocationRelativeTo(null);
f.setTitle("Test");
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.addMouseMotionListener(b);
f.addKeyListener(new Key());
}
}
Run Code Online (Sandbox Code Playgroud)
class在我创建用于移动形状的2DGraphics的球:
public class Ball extends JLabel implements MouseMotionListener{
public Ball(){
}
public static double x = 10;
public static double …Run Code Online (Sandbox Code Playgroud) 我在intellij-idea中有一个java项目。我正在使用 gradle 来构建它。最近我添加了对 Spring Boot 执行器的依赖,从那以后我在启动时遇到这个错误:
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
在那之后我的应用程序仍在运行,但我想摆脱这个错误。
我试图在谷歌上找到答案,但我找不到任何答案。
我将不胜感激任何帮助。谢谢你。
private void button_Clicked_download(MouseEvent e) {
button_dl.setEnabled(false);
System.out.println("Button Clicked.");
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,该按钮看起来已禁用.但是按钮仍然执行MouseEvent下的代码,我看到"Button Clicked".在调试控制台中.
我怎么能这样做,如果单击按钮它会忽略代码并确实被禁用?
我必须限制JTextField中的字符数.我使用以下代码来做到这一点,但问题是我使用虚拟键盘将数据提供给JTextField.因此偏移量始终设置为0.当我输入超过指定数量的字符时,它会重置字段并从头开始执行.例如,如果我的限制是3个字符并且我进入xyz0我的有限文本框,则读取字符z,然后清除该字段并重新启动.所以我留0在了现场.代码如下.
public class JTextFieldLimit extends PlainDocument {
private int limit;
public JTextFieldLimit(int limit) {
super();
this.limit = limit;
}
@Override
public void insertString( int offset, String str, AttributeSet attr ) throws BadLocationException {
if (str == null) return;
System.out.println("from document helper getLength():"+getLength());
System.out.println("from document helper str.length():"+str.length());
System.out.println("from document helper str:"+str);
System.out.println("from document helper attr:"+attr);
System.out.println("from document helper offset:"+offset);
if ((getLength() + str.length()) <= limit) {
super.insertString(offset, str, attr);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Netbeans GUI,我想在jTextField的开头添加3个像素的空间:

我已经在GUI中尝试了setMargin,setInset,但它没有改变任何东西.
我有另一个问题,为什么右下边框不圆?这是我的代码:
Border roundedBorder = new LineBorder(new Color(210,210,210), 1, true);
researchTextField.setBorder(roundedBorder);
Run Code Online (Sandbox Code Playgroud)
非常感谢你,
问候
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Cards extends JFrame {
private GridLayout grid1;
JButton []bt=new JButton[52];
ImageIcon tail=new ImageIcon(getClass().getResource("b1fv.png"));
ImageIcon ori;
public Cards(){
grid1=new GridLayout(7,9,2,2);
setLayout(grid1);
for(int i=0;i<bt.length;i++){
ImageIcon c=new ImageIcon(getClass().getResource(i+1+".png"));
bt[i]=new JButton(c);
bt[i].addActionListener(new RatingMouseListener(i));
add( bt[i]);
}
}
public static void main(String[] args){
Cards frame=new Cards();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1400,700);
frame.setVisible(true);
}
private class RatingMouseListener implements ActionListener {
private int index=0;
public RatingMouseListener(int index) {
this.index = index;
}
public void actionPerformed(ActionEvent e) {
System.out.println("Mouse entered for rating " …Run Code Online (Sandbox Code Playgroud)