Eclipse를 사용 중이며 내 GUI 용 레이블 또는 로고에 이미지를 추가하고 싶습니다.GUI에 이미지를 구현할 수 없습니다.
나는 이것을보고 싶다! 내가 10 평판을 가지고 있겠지 때문에
나는 웹에 그것을 업로드했습니다.(이름 멋진 프로그램는)
import java.awt.*;
import javax.swing.*;
import javax.swing.JFrame;
public class MainClass extends JFrame{ // super class JFrame
// Kind of a tutorial for creating GUI's in java
private JLabel label;
private JLabel label1;
private JButton button;
private JTextField textfeild;
private ImageIcon image1; // image for my logo
public MainClass() {
setLayout (new FlowLayout());
image1 = new ImageIcon (getClass().getResource ("logo.gif")); // declares image
label = new JLabel ("This is the label");
add (label);
label1 = new JLabel (image1); // adds image
add (label1);
textfeild = new JTextField (15);
add (textfeild);
button = new JButton ("Click");
add (button);
}
public static void main(String[] args) {
MainClass gui = new MainClass();
gui.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // creates window
gui.setSize (300,300);
gui.setVisible (true);
gui.pack();
gui.setTitle ("Title");
}
}
프로그램을 컴파일하지만 실행되지 않는 이미지입니다. 나에게
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at JonsCalc.<init>(JonsCalc.java:18)
at JonsCalc.main(JonsCalc.java:38)
''이클립스를 사용 중이고 내 GUI 용 라벨이나 로고에 이미지를 추가하고 싶습니다. 이렇게 보길 원합니다! ""... 그래, 네 질문이 뭐니? 시도 할 때 어떻게됩니까? 예외? 컴파일되지 않습니까? 컴퓨터가 1000 비트까지 폭발합니까? –
프로그램에 넣으려고하는 이미지가 있습니까, 아니면 "멋진 프로그램 이름"이 추가 할 이미지를 나타 냅니까? –
나는 당신의 문제를 추측하고있다. (그리고 우리는 이것을 할 필요가 없어야한다!) 그러나 현재의 GUI는 당신이 원하는 방식으로 배치하지 않을 수도있다. 그렇다면 [레이아웃 관리자 자습서] (http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html)로 이동하여 다양한 레이아웃을 사용하는 방법을 배우십시오. 스윙 GUI에서 사용할 수 있습니다. 이 작업이 끝나면 MigLayout을 다운로드하십시오. –