JFrame当新框架弹出时,我试图禁用"主" .我想要它,所以你不能点击或拖动该帧上的任何东西.我尝试制作新的帧JDialog,但是没有禁用另一帧.我还看了关于这个的另一个帖子,它建议使它成为一个JDialog但它仍然不起作用.我真的需要帮助这样做.谢谢.这是我用来制作的代码JDialog,是他们的任何问题吗?
editDialog=new JDialog(IntroScreen.frame);
Run Code Online (Sandbox Code Playgroud)
IntroScreen.frame 代表"主要"框架.
我正在尝试创建一个只接受数字的JSpinner,但我也想让它读取/响应退格.
public class test {
JFrame frame;
JPanel panel;
JSpinner spinner;
public test()
{
frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(200,200));
panel = new JPanel();
SpinnerNumberModel numSpin = new SpinnerNumberModel(10, 0,1000,1);
spinner = new JSpinner(numSpin);
JFormattedTextField txt = ((JSpinner.NumberEditor) spinner.getEditor()).getTextField();
((NumberFormatter) txt.getFormatter()).setAllowsInvalid(false);
panel.add(spinner);
frame.setContentPane(panel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args)
{
test test = new test();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码只能编号,但这不允许我退格.我在这个网站上找到了一些例子,但是他们是为C写的.
我需要一个监听器,它会不断检查静态布尔值是否已更改,以便我可以在框架上重新绘制组件。有人可以帮助我吗?我真的不太了解听众,也没有和他们一起工作过多少?帮助将不胜感激。
编辑(更清晰):我有两个单独的类,其中类是“主框架”,第二类是 JLabel 的扩展,并为“可点击照片”实现 MouseListner。“主框架”创建照片的实例,当单击照片时,“主框架”应该在面板上绘制照片的描述。这是“主框架”
MenuBar menuBar;
static AnnotationVisual a;
Picture pic;
Picture pic2;
GalleryScreen(int rows, int columns){
this.setBorder(BorderFactory.createEmptyBorder(500,500,0,0));
pic = new Picture("pic1", "Z:/My Documents/Downloads/Ball.jpg", new Coordinate(0,0));
pic2 = new Picture("pic2", "Z:/My Documents/Downloads/hoop.jpg" , new Coordinate(1,0));
this.add(pic);
this.add(pic2);
a = new AnnotationVisual();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if(a.shouldAnnotate()){
FontMetrics size= g.getFontMetrics();
if(getWidth()>=(a.dispX()+size.stringWidth(a.annotationText()))){
g.setColor(Color.white);
g.fillRect(a.dispX()-3,a.dispY()-12,size.stringWidth(a.annotationText())+5,15);
g.setColor(Color.black);
g.drawRect(a.dispX()-3,a.dispY()-12,size.stringWidth(a.annotationText())+5,15);
g.drawString(a.annotationText(), a.dispX(), a.dispY());
}else{
String sub="";
int letters=0;
g.setColor(Color.white);
g.fillRect(a.dispX()-3,a.dispY()-12,getWidth(),15);
g.setColor(Color.black);
for(int i=0;i<a.annotationText().length();i++){
if(a.dispX()+letters+16<=getWidth()){
sub+=a.annotationText().substring(i,i+1);
letters=size.stringWidth(sub);
}else{
sub=sub+"...";
i=a.annotationText().length();
}
}
g.drawRect(a.dispX()-3,a.dispY()-12,size.stringWidth(sub)+3,15);
g.drawString(sub,a.dispX(),a.dispY()); …Run Code Online (Sandbox Code Playgroud) 我一直试图调试这几个小时.该程序应该是一个图形坐标的图形,但我不能得到任何东西甚至不是随机线,但如果我把一个打印声明放在那里它的工作原理.这是paintComponent方法的一个问题.当我在g.drawLine之前打印语句然后打印,但即使我放置一个带坐标(1,3),(2,4)的随机行,它也不会绘制任何行.
import java.awt.*;
import java.util.*;
import javax.swing.*;
public abstract class XYGrapher
{
abstract public Coordinate xyStart();
abstract public double xRange();
abstract public double yRange();
abstract public Coordinate getPoint(int pointNum);
public class Paint extends JPanel
{
public void paintGraph(Graphics g, int xPixel1, int yPixel1, int xPixel2, int yPixel2)
{
super.paintComponent(g);
g.setColor(Color.black);
g.drawLine(xPixel1, yPixel1, xPixel2, yPixel2);
}
public void paintXAxis(Graphics g, int xPixel, int pixelsWide, int pixelsHigh)
{
super.paintComponent(g);
g.setColor(Color.green);
g.drawLine(xPixel, 0, xPixel, pixelsHigh);
}
public void paintYAxis(Graphics g, int yPixel, int …Run Code Online (Sandbox Code Playgroud)