가능한 복제를 클릭은 :
How to display images on JPanels using image paths in Netbeans표시 이미지와 텍스트 문자열이 동시 가능 버튼
나는 버튼과 JPanel의와 GUI를 준비했습니다. JFrame에서 버튼을 클릭하면 3 가지 일이 발생합니다. 원본 패키지의 경로로 지정된 두 개의 큰 이미지가 두 개의 별도 JPanel에 표시되어야하며 빈 JLabel에 작은 텍스트 문자열을 표시해야합니다. 문제는 단추 처리 코드를 작성하는 방법을 알 수 없다는 것입니다. 또한 작동시키기 위해 일부 init 구성 요소를 구현해야하는지 알 수 없습니다. 이 내 프로젝트 인 경우
package db.SuperMarioGFX;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author speterson86
*/
public class EnemyGFX extends javax.swing.JFrame {
/**
* Creates new form EnemyGFX
*/
public EnemyGFX() {
initComponents();
}
/**
* 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"), followed by over 1000 lines of Generated
* Code are below this, but not necessary to include in this code sample!
*/
private void btnBeachKoopaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
/**
* For 'Land[JPanel]' (Panel-container for a set of buttons, not for
* displaying images)
*
* Note that "pbx" is short for "picture box". Unlike VB, I couldn't
* find any so-called picture boxes when I was building my GUI in
* Netbeans, so I hoped JPanels would be the next best thing to use for
* displaying relatively large (roughly 400 x 400 pixels or less each)
* images. Now, here's the 3 things I need to display on my EnemyGFX
* JFrame when the btnBeachKoopa button is clicked on:
*
* Display "GFX01.png" in pbxDefaultBinFile[JPanel]
* Display "Yoshi'sIsland2.zst, Level #$106" text in lblSaveState[JLabel]
* Display "Land1.PNG" in pbxFixedBinFile[JPanel]
*
* So how would I go about making that happen?...
*/
}
[친숙한] (http://stackoverflow.com/q/12964639/230513). – trashgod