Netbeans를 사용하여 GUI를 설계 (예 : lazy : \)하고 수동으로 JFrame에 삼각형을 그리는 데 문제가 있습니다. 스윙 구성 요소는 탭을 누르고 개체에 포커스를 놓을 때까지 '숨겨진'부분입니다. 필자는 picture을 첨부하고 아래 코드를 작성합니다.Java 삼각형 그리기 및 다른 스윙 개체 사용 시도
GUI의 자동 생성 코드는 모두 코드의 initComponents() 부분에 있습니다. 그리고 Triage 생성은 JFrame Paint 메소드의 대체 코드에 있습니다. 오브젝트가 setVisibile (true) 이전에 작성되었으므로 initComponents 코드가 페인트 전에 실행됩니다. setVisible (true)가 불려 가면 (자), 페인트 메소드는 initComponents가 작성한 모든 생성 된 오브젝트를 페인트합니다. 아무 것도 가려지지 않도록 솔루션을 찾고 있습니다.
도움을 주시면 감사하겠습니다.
$/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SimpleClient.java
*
* Created on Sep 22, 2011, 11:38:30 AM
*/
package Assignment3;
import java.awt.Graphics;
/**
*
* @author Mark
*/
public class SimpleClient extends javax.swing.JFrame {
/** Creates new form SimpleClient */
public SimpleClient() {
initComponents();
}
public void paint(Graphics g) {
int[] xPoints = {100, 100, 200};
int[] yPoints = {100, 200, 200};
g.drawPolygon(xPoints, yPoints, 3);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.setText("jTextField1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(103, 103, 103)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(238, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(220, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SimpleClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SimpleClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SimpleClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SimpleClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SimpleClient().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField jTextField1;
// End of variables declaration
}