/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
image editor
Fra : Alan


Dato : 16-12-03 02:22

jeg er i gang med at lave en image editor,
men der er en fejl i programmet som jeg kan ikke finde. Så HjælP!
her er min source:
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;import javax.swing.*;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.EditorKit;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.rtf.RTFEditorKit;
public class QuickPaneProg extends JFrame{   
HTMLEditorKit htmlKit;   
RTFEditorKit rtfKit;      
JFileChooser jfc;   
JEditorPane jep;   
EditorKit currentKit;   
public QuickPaneProg(){      
super("Text Panes");      
htmlKit = new HTMLEditorKit();      
rtfKit = new RTFEditorKit();   
         jep = new JEditorPane();      
jep.setEditorKit(rtfKit);      
jep.setPreferredSize(new Dimension(100,100));   
   JScrollPane jsp = new JScrollPane(jep);            
jfc = new JFileChooser();      FileFilter ff = new FileFilter() {         public
boolean accept(File f)         {            String name =
f.getName().toLowerCase();            if (name.endsWith(".jpg") ||
name.endsWith(".txt") || f.isDirectory())               return
true;            else               return false;         }         public String
getDescription()         {            return "Viewable (*.txt,
*.jpg)";         }               };      jfc.setFileFilter(ff);            JMenuItem open = new
JMenuItem("Open...");         open.addActionListener(new ActionListener()
{            public void actionPerformed(ActionEvent ae){               int ret =
jfc.showOpenDialog(TextPaneProg.this);               if (ret ==
JFileChooser.APPROVE_OPTION){                  File f =
jfc.getSelectedFile();                  String name =
f.getName();                  try                  {                     URL file =
f.getAbsoluteFile().toURL();                     if
(name.toLowerCase().endsWith(".txt")){                        jep.setEditorKit(rtfKit);                        jep.setPage(file);                     }
else {                        jep.setEditorKit(htmlKit);                        jep.setText("<img
src=\""+file.toString()+"\">");                     }                  } catch
(MalformedURLException e)                  {                     e.printStackTrace();                  }
catch (IOException e)                  {                     e.printStackTrace();                  }               }            }         });      JMenu
file = new JMenu("File");      file.add(open);      JMenuBar menu = new
JMenuBar();      menu.add(file);            getContentPane().add(jsp);      setJMenuBar(menu);      setSize(new
Dimension(800,500));      setDefaultCloseOperation(EXIT_ON_CLOSE);      show();   }      public
static void main(String[] args)   { new QuickPaneProg(); }}

 
 
Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408921
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste