2012-08-11 77 views
1

想象一下,我有一臺運行在服務器上的Apache服務器的場景。來自互聯網的用戶來到服務器,並由一個Java Applet迎接,這個Java Applet提示他們從他們的計算機中選擇一個圖像文件。然後使用徽標爲圖像文件蓋章並覆蓋用戶選擇的原始圖像。我把它寫成桌面GUI應用程序。無論如何,直接拿我的基於swing的應用程序,並在網站上運行它?Java小應用程序打開,編輯和保存圖像文件

回答

3

是否有直接帶我的基於swing的應用程序並在網站上運行它?

不是在網站上,而是從網站上。對應用程序Jar進行數字簽名並使用Java Web Start從鏈接啓動它。該應用程序。將需要在啓動文件中請求all-permissions

替代簽名代碼和請求擴展權限,請將I/O轉換爲使用等效的JNLP API服務。用戶將在運行時被提示是否允許該操作。請參閱沙箱demo. of the JNLP API file services瞭解外觀和感覺。

+0

+1,尋找答案:-),認爲有時主要問題出現在第一次用戶登錄的.jar文件:(,我可以訪問我的電腦,我就可以了,看如果我已經將方法保存到這個東西中,我會嘗試提供同樣的鏈接 – 2012-08-11 10:22:48

+0

簽署一個小程序是不可能的 – 2012-08-11 23:22:06

+1

這是不正確的,要麼我或者多次完成了'不可能'的事情 – 2012-08-12 01:03:11

0
Dear Friend here is an GUI that provides user interface to edit images...refer through it 
/* Arpana */ 
import java.awt.BorderLayout; 
import java.awt.Color; 
import java.awt.Container; 
import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.awt.GridLayout; 
import java.awt.Image; 
import java.awt.MediaTracker; 
import java.awt.Toolkit; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.WindowAdapter; 
import java.awt.event.WindowEvent; 
import java.awt.image.BufferedImage; 
import java.awt.image.ConvolveOp; 
import java.awt.image.Kernel; 

import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.border.TitledBorder; 

public class ConvolveApp extends JFrame { 
    CPanel displayPanel; 

    JButton sharpenButton, blurringButton, edButton, resetButton; 

    public ConvolveApp() { 
    super(); 
    Container container = getContentPane(); 

    displayPanel = new CPanel(); 
    container.add(displayPanel); 

    JPanel panel = new JPanel(); 
    panel.setLayout(new GridLayout(2, 2)); 
    panel 
     .setBorder(new TitledBorder(
      "Click a Button to Perform the Associated Operation and Reset...")); 

    sharpenButton = new JButton("Sharpen"); 
    sharpenButton.addActionListener(new ButtonListener()); 
    blurringButton = new JButton("Blur"); 
    blurringButton.addActionListener(new ButtonListener()); 
    edButton = new JButton("Edge Detect"); 
    edButton.addActionListener(new ButtonListener()); 
    resetButton = new JButton("Reset"); 
    resetButton.addActionListener(new ButtonListener()); 

    panel.add(sharpenButton); 
    panel.add(blurringButton); 
    panel.add(edButton); 
    panel.add(resetButton); 

    container.add(BorderLayout.SOUTH, panel); 

    addWindowListener(new WindowAdapter() { 
     public void windowClosing(WindowEvent e) { 
     System.exit(0); 
     } 
    }); 
    //setSize(100,100); 
    setSize(displayPanel.getWidth()+50, displayPanel.getHeight()); 
    setVisible(true); 
    } 
    public static void main(String arg[]) { 
    new ConvolveApp(); 
    } 

    class ButtonListener implements ActionListener { 
    public void actionPerformed(ActionEvent e) { 
     JButton button = (JButton) e.getSource(); 

     if (button.equals(sharpenButton)) { 
     displayPanel.sharpen(); 
     displayPanel.repaint(); 
     } else if (button.equals(blurringButton)) { 
     displayPanel.blur(); 
     displayPanel.repaint(); 
     } else if (button.equals(edButton)) { 
     displayPanel.edgeDetect(); 
     displayPanel.repaint(); 
     } else if (button.equals(resetButton)) { 
     displayPanel.reset(); 
     displayPanel.repaint(); 
     } 
    } 
    } 
} 

class CPanel extends JLabel { 
    Image displayImage; 

    BufferedImage biSrc; 

    BufferedImage biDest; // Destination image is mandetory. 

    BufferedImage bi; // Only an additional reference. 

    Graphics2D big; 

    CPanel() { 
    setBackground(Color.black); 
    loadImage(); 
    setSize(displayImage.getWidth(this), displayImage.getWidth(this)); 
    createBufferedImages(); 
    bi = biSrc; 
    } 

    public void loadImage() { 
    displayImage = Toolkit.getDefaultToolkit().getImage("Desert.jpg"); 
    MediaTracker mt = new MediaTracker(this); 
    mt.addImage(displayImage, 1); 
    try { 
     mt.waitForAll(); 
    } catch (Exception e) { 
     System.out.println("Exception while loading."); 
    } 
    if (displayImage.getWidth(this) == -1) { 
     System.out.println("No jpg file"); 
     System.exit(0); 
    } 
    } 

    public void createBufferedImages() { 
    biSrc = new BufferedImage(displayImage.getWidth(this), displayImage 
     .getHeight(this), BufferedImage.TYPE_INT_RGB); 

    big = biSrc.createGraphics(); 
    big.drawImage(displayImage, 0, 0, this); 

    biDest = new BufferedImage(displayImage.getWidth(this), displayImage 
     .getHeight(this), BufferedImage.TYPE_INT_RGB); 
    } 

    public void sharpen() { 
    float data[] = { -1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f, 
     -1.0f }; 
    Kernel kernel = new Kernel(3, 3, data); 
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, 
     null); 
    convolve.filter(biSrc, biDest); 
    bi = biDest; 
    } 

    public void blur() { 
    float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 
     0.0625f, 0.125f, 0.0625f }; 
    Kernel kernel = new Kernel(3, 3, data); 
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, 
     null); 
    convolve.filter(biSrc, biDest); 
    bi = biDest; 
    } 

    public void edgeDetect() { 
    float data[] = { 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 
     -1.0f }; 

    Kernel kernel = new Kernel(3, 3, data); 
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, 
     null); 
    convolve.filter(biSrc, biDest); 

    bi = biDest; 
    } 

    public void reset() { 
    big.setColor(Color.black); 
    big.clearRect(0, 0, bi.getWidth(this), bi.getHeight(this)); 
    big.drawImage(displayImage, 0, 0, this); 
    bi = biSrc; 
    } 

    public void update(Graphics g) { 
    g.clearRect(0, 0, getWidth(), getHeight()); 
    paintComponent(g); 
    } 

    public void paintComponent(Graphics g) { 
    super.paintComponent(g); 
    Graphics2D g2D = (Graphics2D) g; 

    g2D.drawImage(bi, 0, 0, this); 
    } 
} 
相關問題