2012-07-04 5 views
0

안녕하세요, 자바 애플릿이 있습니다. Eclıpse에서 완벽하게 실행되고 모든 스윙 항목을 표시하지만 html에이 애플릿을 포함하면 애플릿이 표시되지 않거나 브라우저의 일부 항목 만 표시됩니다. 아래는 제 코드입니다. 누군가 내 문제를 도와 주실 수 있습니까?자바 애플릿이 브라우저에 표시되지 않습니다.

import java.applet.Applet; 
import java.awt.*; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 

import javax.swing.ImageIcon; 
import javax.swing.JApplet; 
import javax.swing.JButton; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
import javax.swing.SwingConstants; 

import java.applet.*; 
import java.net.*; 
public class TestApplet extends JApplet implements ActionListener { 

    Button talkToAllButton; 
    Button sendPhotoToAll; 
    int Tikla1Basim, Tikla2Basim; 
    JLabel header; 

    JLabel statusLabel; 
    JLabel posLabel; 
    JLabel idLabel; 
    JLabel iDLabel; 
    JLabel heartRateLabel; 
    JLabel heartRateLabel2; 
    JLabel backgroundLabel; 
    JButton sendPicButton; 
    JButton talkOnOffButton; 
    public void init() { 

     this.setLayout(null); 
     setSize(1200, 900); 


     idLabel=new JLabel(new ImageIcon(getImage(getDocumentBase(), "res/call_sign.png"))); 
     idLabel.setFont(new Font("Serif", Font.BOLD, 20)); 
     idLabel.setBackground(Color.white); 
     idLabel.setForeground(Color.black); 
     idLabel.setOpaque(true); 
     idLabel.setBounds(getWidth()-190,200,180,50); 
     //idLabel.setBorder(border); 
     add(idLabel); 

     iDLabel=new JLabel("NONE",JLabel.CENTER); 
     iDLabel.setFont(new Font("Serif", Font.BOLD, 20)); 
     iDLabel.setBackground(new Color(36,48,24)); 
     iDLabel.setForeground(Color.WHITE); 
     iDLabel.setOpaque(true); 
     iDLabel.setBounds(getWidth()-190,250,180,50); 
     //iDLabel.setBorder(border); 
     add(iDLabel); 

     statusLabel=new JLabel(new ImageIcon(getImage(getDocumentBase(), "res/status_alive.png"))); 
     statusLabel.setFont(new Font("Serif", Font.BOLD, 20)); 
     statusLabel.setBackground(Color.green); 
     statusLabel.setForeground(Color.black); 
     statusLabel.setOpaque(true); 
     statusLabel.setBounds(getWidth()-190,300,180,50); 
     //statusLabel.setBorder(border); 
     add(statusLabel); 

     posLabel=new JLabel("NO DATA"); 
     posLabel.setFont(new Font("Serif", Font.BOLD, 20)); 
     posLabel.setHorizontalAlignment(SwingConstants.CENTER); 
     posLabel.setBackground(Color.green); 
     posLabel.setForeground(Color.WHITE); 
     posLabel.setOpaque(true); 
     posLabel.setBounds(getWidth()-190,350,180,70); 
     //posLabel.setBorder(border); 
     add(posLabel); 

     heartRateLabel=new JLabel(new ImageIcon(getImage(getDocumentBase(), "res/hearth_rate.png"))); 
     heartRateLabel.setFont(new Font("Serif", Font.BOLD, 20)); 
     heartRateLabel.setBackground(Color.red); 
     heartRateLabel.setForeground(Color.black); 
     heartRateLabel.setOpaque(true); 
     heartRateLabel.setBounds(getWidth()-190,450,180,50); 
     //heartRateLabel.setBorder(border); 
     add(heartRateLabel); 

     heartRateLabel2=new JLabel("NO DATA",JLabel.CENTER); 
     heartRateLabel2.setFont(new Font("Serif", Font.BOLD, 20)); 
     heartRateLabel2.setBackground(new Color(180,2,2)); 
     heartRateLabel2.setForeground(Color.WHITE); 
     heartRateLabel2.setOpaque(true); 
     heartRateLabel2.setBounds(getWidth()-190,500,180,50); 
     //heartRateLabel2.setBorder(border); 
     add(heartRateLabel2); 

     sendPicButton=new JButton(new ImageIcon(getImage(getDocumentBase(), "res/send_pic.png"))); 
     sendPicButton.setFont(new Font("Serif", Font.BOLD, 20)); 
     sendPicButton.setBackground(Color.red); 
     sendPicButton.setForeground(Color.black); 
     sendPicButton.setOpaque(true); 
     sendPicButton.setBounds(getWidth()-190,580,180,50); 
     //sendPicButton.setBorder(border); 
     add(sendPicButton); 
     sendPicButton.addActionListener(this); 

     talkOnOffButton=new JButton(new ImageIcon(getImage(getDocumentBase(), "res/talk_off.png"))); 
     talkOnOffButton.setFont(new Font("Serif", Font.BOLD, 20)); 

     talkOnOffButton.setOpaque(true); 
     talkOnOffButton.setBounds(getWidth()-190,650,180,50); 
     //talkOnOffButton.setBorder(border); 
     add(talkOnOffButton); 
     talkOnOffButton.addActionListener(this); 
     //*********************************************************** 
     //isFpsLimited = true; 
     backgroundLabel=new JLabel(new ImageIcon(getImage(getDocumentBase(), "res/bg.png"))); 
     backgroundLabel.setOpaque(true); 
     backgroundLabel.setBounds(getWidth()-200,0,200,800); 
     add(backgroundLabel); 

     ImageIcon headerImg=new ImageIcon(getImage(getDocumentBase(),"res/erlink_header.png")); 
     header=new JLabel(headerImg); 
     header.setBounds(-45, -40, 1800, 200); 

     add(header); 
     sendPhotoToAll = new Button("Send Photo(All)"); 
     sendPhotoToAll.setBounds(850,40, 150, 50); 
     header.add(sendPhotoToAll); 
     talkToAllButton = new Button("Talk(All)"); 
     talkToAllButton.setBounds(850,90, 100, 50); 
     header.add(talkToAllButton); 

     sendPhotoToAll.addActionListener(this); 
     talkToAllButton.addActionListener(this); 
     /*sendPhotoToAll.setLocation(10, 10); 
     sendPhotoToAll.setSize(150, 30); 

     talkToAllButton.setLocation(10, 40); 
     talkToAllButton.setSize(250, 30);*/ 

    } 

    public void actionPerformed(ActionEvent event) { 
    //event things 
    } 
    // TODO overwrite start(), stop() and destroy() methods 
} 
+0

[학습 : Java 애플릿] (http://docs.oracle.com/javase/tutorial/deployment/applet/) – user1329572

+0

AWT를 정당한 이유없이 스윙 구성 요소와 함께 사용하지 마십시오. 'Button' ->'JButton'. 내가 GUI를 화면에 볼 수 있지만 그것이 배열 구성 요소를 원하는 방법이라고 믿기 힘들 찾을 수 있습니다. GUI를 어떻게 보이게 할 것인지 아스키 아트 나 드로잉을 제공 할 수 있습니까? –

답변

2
  1. 사용 레이아웃.
  2. 모든 구성 요소를 추가 한 후 validate()으로 전화하십시오.
  3. EDT에서 GUI를 구성하십시오. 자세한 내용은 Concurrency in Swing을 참조하십시오.
+0

세 가지 좋은 점 – mKorbel

+0

하지만 레이아웃이 아닌 예제를 보았습니다. 실제로 Layouts의 사용을 피하면 내 일이 훨씬 쉬워집니다. 전체 애플릿의 너비와 함께 상단에 큰 배너가 있고 오른쪽에 버튼 목록이 있습니다. 나는 레이아웃을 사용하지 않기 위해 내가 여기서 잘못하고있는 것이 확실하지 않습니다. – dramaticlook

+0

* "하지만 레이아웃이 아닌 예제를 보았습니다."* 나쁜 예입니다. 그들을 무시하라. * "레이아웃 사용을 피하는 것이 실제로 내 일을 훨씬 쉽게합니다." 개발하는 동안, 그러나 일단 배포하면 '모두 붕괴됩니다'. 그것이 당신이 본 '예'의 제공자들이 지적한 것입니다. 2 명 이상의 사람들에게 배포 할 Java GUI를 설계하는 경우 레이아웃이 필수적입니다. See [setLayout (null)은 결코 필요 없다. Ever!] (https://forums.oracle.com/forums/thread.jspa?threadID=1351374) more .. –

관련 문제