누구도 도와 줄 수 있습니까? 아래의 코드를 실행할 때마다 항상 빈 프레임이 반환됩니다. 어디에서 잘못했는지는 알 수 없습니다. 이 디버깅을 도와 줄 수 있습니까? 이미 패널에 구성 요소를 추가하고 프레임에 패널을 추가했지만 여전히 빈 출력을 반환합니다. 이 필요한 것입니다 동안 빈 JFrame 및 JPanel이 표시되지 않았지만 이미 추가되었습니다.
: 여기
는 내가 갖는 출력입니다.import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ButtonGroup;
import javax.swing.BorderFactory;
import javax.swing.UIManager;
import javax.swing.BoxLayout;
import java.awt.GridLayout;
import java.awt.EventQueue;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JRadioButton;
/**
*
* @author Chareux
*/
//Declaring Variables
public class TestUI {
private JFrame frm_main;
private JPanel sr_pnl;
private JLabel sr_lbl;
private JLabel sr_lbl2;
private JLabel ret_optn_lbl;
private JLabel ret_rsn_lbl;
private ButtonGroup ret_ops;
private JTextField sr_txtnum;
private JTextField sr_ret_txtrsn;
private JButton sr_start;
private JRadioButton ret_optn_rdbn_y;
private JRadioButton ret_optn_rdbn_n;
public TestUI(){
start();
}
public void start(){
//Creating the JFrame
frm_main = new JFrame("Service Desk SR Tool");
frm_main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm_main.setSize(500,450);
frm_main.setLocationRelativeTo(null);
frm_main.setResizable(false);
frm_main.setVisible(true);
// the Panel
sr_pnl = new JPanel();
//Components
sr_lbl = new JLabel("SERVICE DESK SR TIMER!");
sr_lbl2 = new JLabel("SR number: ");
sr_txtnum = new JTextField("Enter SR number here..",20);
ret_optn_lbl = new JLabel("Returning Ticket?");
ret_optn_rdbn_y = new JRadioButton("Yes");
ret_optn_rdbn_n = new JRadioButton("No");
ret_rsn_lbl = new JLabel("Reason: ");
sr_ret_txtrsn = new JTextField("Enter Reason number here..",20);
sr_start = new JButton("START!");
//adding the Components to the panel
sr_pnl.add(sr_lbl);
sr_pnl.add(sr_lbl2);
sr_pnl.add(sr_txtnum);
sr_pnl.add(ret_optn_lbl);
sr_pnl.add(ret_optn_rdbn_y);
sr_pnl.add(ret_optn_rdbn_n);
sr_pnl.add(ret_rsn_lbl);
sr_pnl.add(sr_ret_txtrsn);
sr_pnl.add(sr_start);
frm_main.add(sr_pnl,BorderLayout.CENTER);
//ButtonGroup for the radio button
ret_ops = new ButtonGroup();
ret_ops.add(ret_optn_rdbn_y);
ret_ops.add(ret_optn_rdbn_n);
}
public static void main(String[] args) {
new TestUI();
}
}
,'ret_ops.add (ret_optn_rdbn_n)'이후,'. ** 모든 구성 요소를 추가 한 후에 항상 프레임을 ** 표시로 설정해야합니다. – BackSlash
또는'frm_main.validate() 및 frm_main.repaint()'를'start()'메소드의 마지막 행으로 작성하십시오. 컨테이너에 컴포넌트를 추가 한 다음 컨테이너의 visible 속성을 true로 설정하는 것이 가장 좋습니다 :-) –
해당 GUI에서 'Reason :'레이블과 'Reason number here'텍스트 필드 입력 끝 다른 줄에. 나는 그것이 의도하지 않은 걸릴까요? 이 코드에는 많은 문제점이 있습니다. 최상의 도움을 얻으려면 의도 한 레이아웃의 ASCII 아트 (또는 그림)를 게시하십시오. –