All pastes #439010 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-04-14 00:05 UTC
rendered paste body
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.io.*;






public class decrypt extends JFrame implements ActionListener,ItemListener {
JScrollPane pane3 ;
	public decrypt() {
		     super();
		     setTitle("Vigenere");
			    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		        JPanel content =new JPanel(new BorderLayout());
		        setPreferredSize(new Dimension(600,600));
		        this.getContentPane().add(content);
		        setVisible(true);
		        add(content);
		        
		        
		        
		        
		        
		        
		       
		        
		        JMenuBar menu1 =new JMenuBar();
		        setJMenuBar(menu1);
		        
		        
		        
		        JMenu file =new JMenu("File");
		        file.setMnemonic(KeyEvent.VK_F);
		        menu1.add(file);
		        
		        JMenu algo = new JMenu("Alghorithme");
		        algo.setMnemonic(KeyEvent.VK_A);
		        menu1.add(algo);
		        
		        //ouvrir un fichier txt
		        JMenuItem open =new JMenuItem("Open");
		        open.setMnemonic(KeyEvent.VK_0);
		        open.addActionListener(this);
		        file.add(open);
		        //about
		        file.addSeparator();
		        JMenuItem about = new JMenuItem("About");
		        about.setMnemonic(KeyEvent.VK_1);
		        about.addActionListener(this);
		        file.add(about);
		        //pour fermer l'appli
		        file.addSeparator();
		        JMenuItem exit= new JMenuItem("Exit");
		        exit.setMnemonic(KeyEvent.VK_X);
		        exit.addActionListener(this);
		        file.add(exit);
		        
		        //pour choisir entre le type d'algo
		        ButtonGroup al = new ButtonGroup();
		        
		        JRadioButtonMenuItem select =  new JRadioButtonMenuItem("ASCII",true);
		        select.addItemListener(this);
		        select.setMnemonic(KeyEvent.VK_C);
		        al.add(select);
		        algo.add(select);
		        
		        select= new JRadioButtonMenuItem("Vigenere",false);
		        select.addItemListener(this);
		        select.setMnemonic(KeyEvent.VK_V);
		        al.add(select);
		        algo.add(select);
		        
		        //choisir n 
		        String[]fois = new String[]{"1","2","3", "4"};
		        JComboBox N =new JComboBox(fois);
		        N.setEditable(true);
		        N.setSize(new Dimension(5,3) );
		        N.addActionListener(this);
		        menu1.add(N);
		        
		        //la cle
		        JTextField cle = new JTextField("entre la cle ici....",20);
		        cle.setFont(new Font("Sans-Serif",Font.BOLD,14));
		        cle.addActionListener(this);
		        menu1.add(cle);
		        pack();
		        
		        JButton button =new JButton("Crypt");
	            button.setMnemonic(KeyEvent.VK_C);
	            button.addActionListener(this);
	            menu1.add(button);
	            
	            JButton button1=new JButton("Decrypt");
	            button1.setMnemonic(KeyEvent.VK_D);
	            button1.addActionListener(this);
	            menu1.add(button1);
	            //entre/sorite
	            JTextArea text1 = new JTextArea("entrer le texte ici",5,5);
	            JTextArea text2 = new JTextArea("le resultat",5,5);
	            text1.setPreferredSize(new Dimension(20,40));
	            text2.setPreferredSize(new Dimension(20,40));
	            JScrollPane pane1 =new JScrollPane(text1);
	            pane1.setPreferredSize(new Dimension(290,290));
	            JScrollPane pane2 =new JScrollPane(text2);
	            pane2.setPreferredSize(new Dimension(290,290));
	            
	            pane3=pane1;
	            JSplitPane trenn =new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,pane1,pane2);
	              content.add(trenn);
	            
	            
	}

   public void actionPerformed(ActionEvent e)  {
	  String m ;
	  int n ; 
	  JMenuItem item =(JMenuItem)e.getSource();
	   String text = item.getText();
	   if (text == "Exit"){
		   
		   setVisible(false);
		   System.exit(0);
	   
	   }
   
       if (text == "Open"){
    	JFileChooser txt = new JFileChooser();
    	int choice = txt.showOpenDialog(this);
    	if (choice == JFileChooser.APPROVE_OPTION){
    		File fichier = txt.getSelectedFile();
    		try{
    			BufferedReader rd = new BufferedReader(new FileReader(fichier));
    			StringBuilder sb = new StringBuilder();
    			String line = null ;
    			while(null != (line =rd.readLine())){
    			sb.append(line+"\n");	
    		}
            rd.close();  	
    		JTextArea text1= new JTextArea(sb.toString());
    		pane3.setViewportView(text1);
    		}catch (FileNotFoundException e1){
    			e1.printStackTrace();
    		}catch (IOException ignored){
    			ignored.printStackTrace();
    		}
    		
    		
    	}
    	   
       }
       if (text=="About"){
    	   about bf =new about();
    		  
    		   
    	   }
       
   if(e.getSource() instanceof JComboBox){
	   JComboBox item2 =(JComboBox)e.getSource();
	   String value = null ;
	   if(item2.getSelectedIndex()>0){
		   value=(String)item2.getSelectedItem();
		   
	   }else{
		   value = item2.getEditor().getItem().toString();
		   
		   
	   }
    
    m= value ;
    n=Integer.parseInt(m);
   }
   
   
   
   }
   
   
  
    public void itemStateChanged(ItemEvent e){
    	 JRadioButtonMenuItem item = (JRadioButtonMenuItem)e.getItem();
    	 String c =item.getText();
    }
	
    public static void main(String[]args){
	       decrypt kf=new decrypt();
}

}