1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class UnicodeTextWriter extends JFrame{ private JLabel lchar[]=null; private JTextArea ta=null; private JButton bsave=null; public UnicodeTextWriter(){ super("Unicode Text Writer"); setSize(800,600); JPanel ptop=new JPanel(); ptop.setLayout(new FlowLayout()); ptop.setPreferredSize(new Dimension(800,150)); lchar=new JLabel[256]; char c=0x2200; for(int i=0;i<lchar.length;i++){ lchar[i]=new JLabel(c+""); lchar[i].setBorder(BorderFactory.createLineBorder(Color.black)); lchar[i].addMouseListener(new MouseHandler()); ptop.add("Center",lchar[i]); c++; } ta=new JTextArea(); ta.setColumns(20); bsave=new JButton("Save"); bsave.addActionListener(new ButtonHandler()); JPanel pmain=new JPanel(); pmain.setLayout(new BorderLayout()); pmain.add("North",ptop); pmain.add("Center",ta); pmain.add("South",bsave); add(pmain); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); show(); } class MouseHandler implements MouseListener{ /* public void mouseMoved(MouseEvent e){ } public void mouseDragged(MouseEvent e){ }*/ public void mouseEntered(MouseEvent e){ } public void mouseExited(MouseEvent e){ } public void mouseReleased(MouseEvent e){ } public void mousePressed(MouseEvent e){ } public void mouseClicked(MouseEvent e){ for(int i=0;i<lchar.length;i++){ if(e.getSource()==lchar[i]){ int pos=ta.getCaretPosition(); ta.insert(lchar[i].getText(),pos); } } } } class ButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent ex){ String stemp=ta.getText(); try { FileOutputStream fos = new FileOutputStream("test.txt"); Writer out = new OutputStreamWriter(fos, "UTF8"); out.write(stemp); out.close(); } catch(Exception exx) { } } } public static void main(String[] args){ new UnicodeTextWriter(); } } |
Tuesday, April 12, 2016
Math Symbols in Notepad
The primary function of this program is to insert mathematical symbols into a text editor (notepad). The class JLabel is used to display the symbols.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment