好吧,JOptionPane
文本顯示在JFrame
窗口中,甚至我的CS教授都不知道爲什麼。這是一個簡單繪製3行的程序,但無論使用哪種編譯器,它都在JFrame窗口中顯示JOptionPane
文本。繼承人我的代碼。JOptionPane在JFrame中顯示的文字
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.JFrame;
public class Lab5_1 extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
String ia = JOptionPane.showInputDialog ("Enter the beginning x point of the line");
String iab = JOptionPane.showInputDialog ("Enter the beginning y point of the line");
String ja = JOptionPane.showInputDialog ("Enter the end x point of the line");
String jab = JOptionPane.showInputDialog ("Enter the end y point of the line");
int jx = Integer.parseInt(ja);
int jy = Integer.parseInt(jab);
int ix = Integer.parseInt(ia);
int iy = Integer.parseInt(iab);
String iac = JOptionPane.showInputDialog ("Enter the beginning x point of the line");
String iabc = JOptionPane.showInputDialog ("Enter the beginning y point of the line");
String jac = JOptionPane.showInputDialog ("Enter the end x point of the line");
String jabc = JOptionPane.showInputDialog ("Enter the end y point of the line");
int jxb = Integer.parseInt(jac);
int jyb = Integer.parseInt(jabc);
int ixb = Integer.parseInt(iac);
int iyb = Integer.parseInt(iabc);
String iad = JOptionPane.showInputDialog ("Enter the beginning x point of the line");
String iabd = JOptionPane.showInputDialog ("Enter the beginning y point of the line");
String jad = JOptionPane.showInputDialog ("Enter the end x point of the line");
String jabd = JOptionPane.showInputDialog ("Enter the end y point of the line");
int jxc = Integer.parseInt(jad);
int jyc = Integer.parseInt(jabd);
int ixc = Integer.parseInt(iad);
int iyc = Integer.parseInt(iabd);
g.drawLine(ix,iy,jx,jy);
g.drawLine(ixb,iyb,jxb,jyb);
g.drawLine(ixc,iyc,jxc,jyc);
}
public static void main(String[] args) {
Lab5_1 panel = new Lab5_1();
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(500, 290);
application.setVisible(true);
}
}
請不要將圖片作爲外部鏈接發佈。鏈接可能在未來破裂。 Stackoverflow支持添加圖像;) –
沒有足夠的「聲望點」來做到這一點 –
當你的組件需要被繪製時調用PaintComponent,所以每次你的JOptionPane被顯示,每一次... – MadProgrammer