Important alert: (current site time 7/15/2013 3:34:10 PM EDT)
 

VB icon

MicroSoft Processor

Email
Submitted on: 5/31/2004 1:22:38 PM
By: gitsol  
Level: Advanced
User Rating: By 1 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 6226
(About the author)
 
     to make a MS WORd
 

HTML:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//HTML for :MicroSoft Processor
//**************************************
no
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: MicroSoft Processor
// Description:to make a MS WORd
// By: gitsol
//
// Inputs:no
//
// Returns:output
//
// Assumes:no
//
// Side Effects:no
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4240&lngWId=2//for details.//**************************************

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
 
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.text.rtf.*;
import javax.swing.undo.*;
public class MsWord extends JFrame {
 protected JTextArea textArea;
 protected StyleContext styleContext; 
 protected DefaultStyledDocument dSDoc;
 protected RTFEditorKit rtfKit;
 protected JFileChooser fileChooser;
 protected JDesktopPane theDesktop;
 private JComboBox ComboBoxDemo2; 
 
 private Color colorValues [] = { Color.blue, Color.yellow, Color.red,Color.green,Color.cyan,Color.black,Color.gray,Color.pink,Color.orange,Color.magenta,Color.white};
 private JRadioButtonMenuItem colorItems [],colorItems1 [];
 private JCheckBoxMenuItem styleItems [];
 public JCheckBoxMenuItem fonts[];
 private JRadioButtonMenuItem fontSize1 []; 
 private JRadioButtonMenuItem items[];
 private JPopupMenu popupMenu;
 private ButtonGroup fontSizeGroup,fontGroup, colorGroup,colorGroup1;
 private int style;
 public MsWord() {
	super("Word Processor");
	setSize(800,580);
	textArea = new JTextArea();
	rtfKit = new RTFEditorKit();
styleContext = new StyleContext();
dSDoc = new DefaultStyledDocument(styleContext);
textArea.setDocument(dSDoc);
	 
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane ps = new JScrollPane(textArea,v,h);
getContentPane().add(ps, BorderLayout.CENTER);
JMenuBar menuBar = createMenuBar();
setJMenuBar(menuBar);
fileChooser = new JFileChooser(); 
fileChooser.setCurrentDirectory(new File("."));
		
	WindowListener wndCloser = new WindowAdapter() {
	public void windowClosing(WindowEvent e) {
 		System.exit(0);
		}
};
addWindowListener(wndCloser); 
setVisible(true);
 }
 protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
		
JToolBar toolBar=new JToolBar();
JToolBar toolBar2=new JToolBar();
JMenu mFile = new JMenu("File");
mFile.setMnemonic('f');
JMenu mEdit=new JMenu("Edit");
mEdit.setMnemonic('E');
JMenu mFormat=new JMenu("Format");
mFormat.setMnemonic('o');
		
JMenu mTool=new JMenu("Tool");
mTool.setMnemonic('T');
menuBar.add(mFile);
menuBar.add(mEdit);
menuBar.add(mFormat);
menuBar.add(mTool);
/////////////////////////////FILE MENU START //////////////////////////////
//............................NEW IN FILE MENU ..........................
 theDesktop=new JDesktopPane();
	 getContentPane().add(theDesktop);
ImageIcon iconNew = new ImageIcon("new.gif");
Action actionNew = new AbstractAction("New", iconNew) { 
 public void actionPerformed(ActionEvent e) {
JInternalFrame frame=new JInternalFrame
 ("New",true,true,true,true);
Container container=frame.getContentPane();
				 
			int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
	JScrollPane pane=new JScrollPane(textArea,v,h);
				 
		container.add(pane); 
frame.pack();
 		theDesktop.add(frame);
		frame.setVisible(true);
 		frame.setSize(780,400);
 }
};
		
JMenuItem item =mFile.add(actionNew); 
item.setMnemonic('n');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 
 KeyEvent.CTRL_MASK));
toolBar.add(actionNew);	 
	
//............................OPEN IN FILE ...........................
ImageIcon iconOpen = new ImageIcon("open.gif");
Action actionOpen = new AbstractAction("Open..", iconOpen) { 
 public void actionPerformed(ActionEvent e) {
 
Thread runner = new Thread() {
 public void run() {
if (fileChooser.showOpenDialog(MsWord.this) != 
JFileChooser.APPROVE_OPTION)
 return;
MsWord.this.repaint();
File fChoosen = fileChooser.getSelectedFile();
try {
 InputStream in = new FileInputStream(fChoosen);
 dSDoc = new DefaultStyledDocument(styleContext);
 rtfKit.read(in, dSDoc, 0);
 textArea.setDocument(dSDoc);
 in.close();
} 
catch (Exception ex) {
 ex.printStackTrace();
}
 }
};
runner.start();
 }
};
item = mFile.add(actionOpen); 
item.setMnemonic('o');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, 
 KeyEvent.CTRL_MASK));
	 	 
toolBar.add(actionOpen);	 
//...........................SAVE AS IN FILE .................................
ImageIcon iconSave = new ImageIcon("save.gif");
Action actionSave = new AbstractAction("Save As..", iconSave) {
 public void actionPerformed(ActionEvent e) {
Thread runner = new Thread() {
 public void run() {
if (fileChooser.showSaveDialog(MsWord.this) !=
 JFileChooser.APPROVE_OPTION)
 return;
MsWord.this.repaint();
File fChoosen = fileChooser.getSelectedFile();
try {
 OutputStream out = new FileOutputStream(fChoosen);
 rtfKit.write(out, dSDoc, 0, dSDoc.getLength());
 out.close();
} 
catch (Exception ex) {
 ex.printStackTrace();
}
fileChooser.rescanCurrentDirectory();
 }
};
runner.start();
 }
};
item = mFile.add(actionSave); 
item.setMnemonic('s');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 
 KeyEvent.CTRL_MASK)); 
toolBar.add(actionSave);
mFile.addSeparator();
 
//.............................PAGE SET UP ................................
Action actionPage = new AbstractAction("Page setup") { 
 public void actionPerformed(ActionEvent e) {
 
JInternalFrame frame=new JInternalFrame
 ("Page setup",true,true,true,true);
 Container c=frame.getContentPane();
				 PageSetUp pa=new PageSetUp();
				 
				 
				 c.add(pa,BorderLayout.CENTER); 
 frame.pack();
 				 theDesktop.add(frame);
				 frame.setVisible(true);
 				 frame.setSize(450,500);
	 }
};
item = mFile.add(actionPage);
item.setMnemonic('P');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 
 KeyEvent.CTRL_MASK)); 
//.............................. EXIT IN FILE .............................
Action actionExit = new AbstractAction("Exit") { 
 public void actionPerformed(ActionEvent e) {
System.exit(0);
 }
};
item = mFile.add(actionExit); 
item.setMnemonic('x');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 
 KeyEvent.ALT_MASK)); 
//**********************************END FILE MENU ***********************
/////////////////////////////////////EDIT START ////////////////////////
mEdit.addSeparator();	 
	 
//.............................. EDIT CUT COPY PASTE ...........................
Action action = new AbstractAction("Copy",new ImageIcon("copy.gif")) 
{ 
 public void actionPerformed(ActionEvent e) {
textArea.copy();
 }
};
item = mEdit.add(action); 
item.setMnemonic('c');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 
 KeyEvent.CTRL_MASK));
toolBar.add(action); 
 
//................................. CUT IN EDIT ............................
action = new AbstractAction("Cut", 
 new ImageIcon("cut.gif")) 
{ 
 public void actionPerformed(ActionEvent e) {
textArea.cut();
 }
};
item = mEdit.add(action); 
item.setMnemonic('t');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,KeyEvent.CTRL_MASK));
	toolBar.add(action); 
 
//................................ PASTE IN EDIT ...............................
 action = new AbstractAction("Paste", 
 new ImageIcon("paste.gif")) 
{ 
 public void actionPerformed(ActionEvent e) {
textArea.paste();
 }
};
item = mEdit.add(action); 
item.setMnemonic('p');
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,KeyEvent.CTRL_MASK));
	 toolBar.add(action);
//***************************** END EDIT ***************************
/////////////////////////////// FORMAT START ////////////////////////
//...........................FONT COLOR IN FORMAT MENU .................
 String colors[] = {"Blue", "Yellow","Red","Green","Cyan","Black","Gray","Pink","Orange","Magenta","White"};
 JMenu colorMenu = new JMenu ("FontColor");
 colorMenu.setMnemonic('C');
 colorItems = new JRadioButtonMenuItem [colors.length];
 colorGroup = new ButtonGroup ();
 ItemHandler itemHandler = new ItemHandler ();
 for (int count=0; count<colors.length; count++) {
 colorItems [count] = new JRadioButtonMenuItem (colors [count]);
 colorMenu.add (colorItems[count]);
 colorGroup.add(colorItems[count]);
 colorItems[count].addActionListener (itemHandler);
 }
 colorItems [0].setSelected (true);
 mFormat.add(colorMenu);
//....................... BACK GROUND COLOR IN FORMAT ....................
 String colors1[] = {"Blue", "Yellow","Red","Green","Cyan","Black","Gray","Pink","Orange","Magenta","White"};
 JMenu colorMenu1 = new JMenu ("BackGroundColor");
 colorMenu1.setMnemonic('B');
 colorItems1 = new JRadioButtonMenuItem [colors1.length];
 colorGroup1 = new ButtonGroup ();
 ItemHandler itemHandler1 = new ItemHandler ();
 for (int count=0; count<colors1.length; count++) {
 colorItems1 [count] = new JRadioButtonMenuItem (colors1 [count]);
 colorMenu1.add (colorItems1[count]);
 colorGroup1.add(colorItems1[count]);
 colorItems1[count].addActionListener (itemHandler1);
 }
 colorItems [0].setSelected (true);
 mFormat.add(colorMenu1);
 
/// .................................FONT IN FORMAT ............................
 String fontNames [] = {"Serif", "Monospaced","SansSerif","Arial","Arial Narrow","Monotype Corsiva","Arial Black",
"Bool Antique","Default","Dialog","Bookman Old Style","Georgia","Century Gothic","Lucida Console","Comic Sans MS","Verdana","Franklin Gothic Medium","Impact","Lucida Sans Unicode","Sylfaen"};
 JMenu fontMenu = new JMenu ("Font");
 fontMenu.setMnemonic ('n');
 fonts = new JCheckBoxMenuItem [fontNames.length];
 fontGroup = new ButtonGroup ();
 for (int count=0; count<fonts.length; count++) {
 fonts [count] = new JCheckBoxMenuItem (fontNames[count]);
 fontMenu.add (fonts[count]);
 fontGroup.add(fonts[count]);
 fonts[count].addActionListener (itemHandler);
 }
 fonts [0].setSelected (true);
 mFormat.add(fontMenu);
 
///.......................FONT STYLE IN FORMAT .........................
String styleNames [] = {"Plain","Bold","Italic","Bold & Italic"};
 JMenu styleMenu = new JMenu ("Style");
 styleMenu.setMnemonic ('S');
 styleItems = new JCheckBoxMenuItem [styleNames.length];
 StyleHandler styleHandler = new StyleHandler ();
 for (int count=0; count<styleNames.length; count++) {
 styleItems [count] = new JCheckBoxMenuItem (styleNames[count]);
 styleMenu.add (styleItems[count]);
 styleItems[count].addItemListener (styleHandler);
 }
 mFormat.add(styleMenu);
	 
//.............................. FONT SIZE START ..........................
String fontSize [] = {"5","7","9","10","11","12","14","16","18","20","30","40","48","60","72","85"};
 JMenu font1Menu = new JMenu ("FontSize");
 font1Menu.setMnemonic ('z');
 fontSize1 = new JRadioButtonMenuItem [fontSize.length];
 fontSize1Handler fontSizeHandler = new fontSize1Handler ();
 fontSizeGroup = new ButtonGroup ();
 for (int count=0; count<fontSize.length; count++) {
 fontSize1[count] = new JRadioButtonMenuItem (fontSize[count]);
 font1Menu.add (fontSize1[count]);
 fontSizeGroup.add(fontSize1[count]);
 fontSize1[count].addItemListener (fontSizeHandler);
 }
	mFormat.add(font1Menu);
 //****************************** END FORMAT ************************
////////////////////////////////DRAWING IN TOOL/////////////////
 
 JMenuItem draw=new JMenuItem("Draw");
 mTool.add(draw);
 draw.addActionListener(new ActionListener()
 {
 	public void actionPerformed(ActionEvent ae)
 	{	
		new Painter();
		 
	}
});
JMenuItem date=new JMenuItem("Date Setting");
 mTool.add(date);
 date.addActionListener(new ActionListener()
 {
 	public void actionPerformed(ActionEvent ae)
 	{	
		JInternalFrame frame=new JInternalFrame
("New",true,true,true,true);
Container container=frame.getContentPane();
DatePro pro=new DatePro();
		container.add(pro); 
frame.pack();
 		theDesktop.add(frame);
		frame.setVisible(true);
 		frame.setSize(400,400);
		 
	}
});
///////////////////////////////TOOL BAR////////////////////////////
 	JButton but1=new JButton(new ImageIcon("art.gif"));
		but1.setToolTipText("World Art");
		but1.addActionListener(new ActionListener()
		{
		public void actionPerformed(ActionEvent ae)
		{ 				
 JInternalFrame frame=new JInternalFrame
 ("Art Gallery",true,true,true,true);
 Container c=frame.getContentPane();
		 MyPanelTest pa=new MyPanelTest();
				 				 
				 c.add(pa,BorderLayout.CENTER); 
 frame.pack();
 			 theDesktop.add(frame);
				 frame.setVisible(true);
 				 frame.setSize(450,400);	 
		}
		});
		toolBar2.add(but1);
		
		JButton but2=new JButton(new ImageIcon("clip.gif"));
		but2.setToolTipText("Clip Art");
		toolBar.add(but2);
		
		JButton but3=new JButton(new ImageIcon("col.gif"));
		but3.setToolTipText("Fill Color");		 
		toolBar2.add(but3);
				
		JButton but4=new JButton(new ImageIcon("scene.gif"));
		but4.setToolTipText("Image");
		toolBar2.add(but4);
		
		JButton but5=new JButton(new ImageIcon("box.gif"));
		but5.setToolTipText("Boxes");
		toolBar2.add(but5);
		JButton but11=new JButton(new ImageIcon("bol.gif"));
		but11.setToolTipText("Bold");
		
		but11.addActionListener(new ActionListener()
		{
		public void actionPerformed(ActionEvent ae)
		{ 
				style+=Font.BOLD;
				textArea.setFont (new Font (textArea.getFont().getName(),style,textArea.getFont().getSize()));
				repaint();
		}
		});		
		toolBar.add(but11);
		JButton but12=new JButton(new ImageIcon("ital.gif"));
		but12.setToolTipText("Italic");
		but11.addActionListener(new ActionListener()
		{
		public void actionPerformed(ActionEvent ae)
		{
				style+=Font.ITALIC;
				textArea.setFont (new Font (textArea.getFont().getName(),style,textArea.getFont().getSize()));
		repaint();
			}
		});		
		toolBar.add(but12);
		JButton but13=new JButton(new ImageIcon("under.gif"));
		but13.setToolTipText("UnderLine");
		toolBar.add(but13);
	//////////LIST /////////////	
	String fontN[] = {"Serif", "Monospaced","SansSerif","Arial","Arial Narrow","Monotype Corsiva","Arial Black",
"Bool Antique","Default","Dialog","Bookman Old Style","Georgia","Century Gothic","Lucida Console","Comic Sans MS","Verdana","Franklin Gothic Medium","Impact","Lucida Sans Unicode","Sylfaen"};
	 
	JComboBox jc=new JComboBox(fontN);
	jc.setEditable(true);
	jc.setSelectedIndex(8);
	jc.addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent ae)
		{
			JComboBox jb=(JComboBox)ae.getSource();
			int index=(int)jb.getSelectedIndex();
			textArea.setFont(new Font(fonts[index].getText(),style,textArea.getFont().getSize()));
		}
	});
 
	toolBar.add(jc); 
	///////////FONT/////////
JComboBox jc2 = new JComboBox();
jc2.addItem("Normal");
jc2.addItem("Heading 1");
jc2.addItem("Heading 2");
jc2.addItem("More..");
	toolBar.add(jc2);
////////////////////////////COMBO BOXES OF SIZE///////////////////
	String font[]={"5","7","9","10","11","12","14","16","18","20","30","40","48","60","72","85"};
JComboBox jcomb = new JComboBox(font);
	jcomb.setEditable(true);
	jcomb.setSelectedIndex(5);
	 
	jcomb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String font = (String)cb.getSelectedItem();
	 if (font=="5")
 textArea.setFont (new Font(textArea.getFont().getName(), style,5));
	 if (font=="7")
 textArea.setFont (new Font(textArea.getFont().getName(), style,7));
	 if (font=="9")
 textArea.setFont (new Font(textArea.getFont().getName(), style,9));
	 if (font=="10")
 textArea.setFont (new Font(textArea.getFont().getName(), style,10));
	 if (font=="11")
 textArea.setFont (new Font(textArea.getFont().getName(), style,11));
	 if (font=="12")
 textArea.setFont (new Font(textArea.getFont().getName(), style,12));
	 if (font=="14")
 textArea.setFont (new Font(textArea.getFont().getName(), style,14));
	 if (font=="16")
 textArea.setFont (new Font(textArea.getFont().getName(), style,16));
	 if (font=="18")
 textArea.setFont (new Font(textArea.getFont().getName(), style,18));
	 if (font=="20")
 textArea.setFont (new Font(textArea.getFont().getName(), style,20));
	 if (font=="30")
 textArea.setFont (new Font(textArea.getFont().getName(), style,30));
	 if (font=="40")
 textArea.setFont (new Font(textArea.getFont().getName(), style,40));
	 if (font=="48")
 textArea.setFont (new Font(textArea.getFont().getName(), style,48));
	 if (font=="60")
 textArea.setFont (new Font(textArea.getFont().getName(), style,60));
	 if (font=="72")
 textArea.setFont (new Font(textArea.getFont().getName(), style,72));
	 if (font=="85")
 textArea.setFont (new Font(textArea.getFont().getName(), style,85)); 
	 
 textArea.setFont (new Font ( textArea.getFont().getName(),style,textArea.getFont().getSize()));
 repaint ();
 
}
});
	toolBar.add(jcomb);
 
/////////////////////////////////////
		 
	getContentPane().add(toolBar,BorderLayout.NORTH);
		getContentPane().add(toolBar2,BorderLayout.SOUTH);
	
	 
		
		
//////////////////////////END TOOLBAR////////////////////////////////////////////		 
	 
//////////////////////CONSTRUCTOR END///////////////////////////////////////
return menuBar;
}
////////////////////////////ITEM HANDLER FOR FORMAT ////////////////////
 private class ItemHandler implements ActionListener {
 public void actionPerformed (ActionEvent event) {
for (int count =0; count<colorItems.length; count++)
if (colorItems[count].isSelected ()) {
 textArea.setForeground (colorValues [count]);
 break;
}
for (int count =0; count<colorItems1.length; count++)
if (colorItems1[count].isSelected ()) {
 textArea.setBackground (colorValues [count]);
 break;
}
for (int count =0; count<fonts.length; count++)
if (event.getSource ()== fonts[count]) {
 textArea.setFont (new Font (fonts [count].getText(),style,textArea.getFont().getSize()));
 break;
}
}
 }
//////////////////////////END HANDLER OF FORMAT /////////////////////
/////////////////////////STYLE HANDLER /////////////////////////
private class StyleHandler implements ItemListener {
 public void itemStateChanged (ItemEvent e) {
 style=0;
 if (styleItems [0].isSelected ())
 style+=Font.PLAIN;
	 if (styleItems [1].isSelected ())
 style+=Font.BOLD;
	 if (styleItems [2].isSelected ())
 style+=Font.ITALIC;
 if (styleItems [3].isSelected ())
 style+=Font.BOLD + Font.ITALIC;
 textArea.setFont (new Font (textArea.getFont().getName(),style,textArea.getFont().getSize()));
 repaint ();
 }
}
////////////////////////////END STYLE HANDLER ///////////////////
//////////////////////////////START FONT SIZE HANDLER ////////////////
private class fontSize1Handler implements ItemListener {
 public void itemStateChanged (ItemEvent e) {
 if (fontSize1 [0].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,5));
	 if (fontSize1 [1].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,7));
	 if (fontSize1 [2].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,9));
 if (fontSize1 [3].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,10));
	 if (fontSize1 [4].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,11));
	 if (fontSize1 [5].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,12));
	 if (fontSize1 [6].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,14));
	 if (fontSize1 [7].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,16));
	 if (fontSize1 [8].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,18));
	 if (fontSize1 [9].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,20));
	 if (fontSize1 [10].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,30));
	 if (fontSize1 [11].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,40));
	 if (fontSize1 [12].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,48));
	 if (fontSize1 [13].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,60));
	 if (fontSize1 [14].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,72));
	 if (fontSize1 [15].isSelected ())
 textArea.setFont (new Font(textArea.getFont().getName(), style,85));
 textArea.setFont (new Font ( textArea.getFont().getName(),style,textArea.getFont().getSize()));
 repaint ();
 }
}
//////////////////////////////END FONT SIZE HANDLER//////////////
/////////////////////////////////////////////////////////////
public static void main(String args[]){
		MsWord replace=new MsWord();
		replace.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
////////////////////////////PAITNER CLASS ///////////////////
 private class Painter extends JFrame {
	private int xValue=-10, yValue=-10;
	public Painter(){
		getContentPane().add(
			new Label("Drag the mouse to Draw"),
			BorderLayout.SOUTH);
		addMouseMotionListener(
			new MouseMotionAdapter(){
				public void mouseDragged(MouseEvent event){
					xValue=event.getX();
					yValue=event.getY();
					repaint();
				}
			}
		);
		setSize(750,500);
		show();
	}
	public void paint(Graphics g){
		g.fillOval(xValue,yValue,6,3);
}
////////////////////////////END PAINTER CLASS ////////////////////////
/////////////////////////////////////////////////////////////////////////
	 
 }
 
}
////////////////////////////////mY PANEL FOR WORD ART//////////////////
 class MyPanelTest extends JPanel
{
	private ImageIcon imageIcon;
	public MyPanelTest()
	{
		imageIcon=new ImageIcon("gallery.gif");
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		imageIcon.paintIcon(this,g,0,0);
	}
	public Dimension getPreferredDSize()
	{
		return new Dimension(imageIcon.getIconWidth(),imageIcon.getIconHeight());
	}
 
} 
//////////////////////////PAGE SETUP CLASS ///////////////////
class PageSetUp extends JPanel
{
	private ImageIcon imageIcon;
	public PageSetUp()
	{
		imageIcon=new ImageIcon("pageset.gif");
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		imageIcon.paintIcon(this,g,0,0);
	}
	public Dimension getPreferredDSize()
	{
		return new Dimension(imageIcon.getIconWidth(),imageIcon.getIconHeight());
	}
 
} 
/////////////////////////////////////////////////////////////////
 class DatePro extends JPanel {
static JFrame frame;
JLabel result;
String currentPattern;
public DatePro() {
String[] pattern = { 
 "dd MM yyyy",
 "dd.MM.yy", 
 "MM/dd/yy",
 "yyyy.MM.dd",
 "MM d, ''yy",
 };
currentPattern = pattern[0];
 
JLabel patternLabel1 = new JLabel("Enter the pattern string or");
JLabel patternLabel2 = new JLabel("select one from the list:");
JComboBox patternList = new JComboBox(pattern);
patternList.setEditable(true);
patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
patternList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String newSelection = (String)cb.getSelectedItem();
currentPattern = newSelection;
reformat();
}
});
JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEFT);
result = new JLabel(" ");
result.setForeground(Color.black);
result.setBorder(BorderFactory.createCompoundBorder(
 BorderFactory.createLineBorder(Color.black),
 BorderFactory.createEmptyBorder(5,5,5,5)
));
 
JPanel patternPanel = new JPanel();
patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.Y_AXIS));
patternPanel.add(patternLabel1);
patternPanel.add(patternLabel2);
patternPanel.add(patternList);
JPanel resultPanel = new JPanel();
resultPanel.setLayout(new GridLayout(0, 1));
resultPanel.add(resultLabel);
resultPanel.add(result);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
add(patternPanel);
add(Box.createRigidArea(new Dimension(0, 10)));
add(resultPanel);
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
 
reformat();
		 
} // constructor
 
public void reformat() {
Date today = new Date();
SimpleDateFormat formatter = 
new SimpleDateFormat(currentPattern);
try {
String dateString = formatter.format(today);
result.setForeground(Color.black);
result.setText(dateString);
} catch (IllegalArgumentException iae) {
result.setForeground(Color.red);
result.setText("Error: " + iae.getMessage());
}
}
	public static void main(String s[]) {
 frame = new JFrame("ComboBoxDemo2");
 frame.addWindowListener(new WindowAdapter() {
 public void windowClosing(WindowEvent e) {
 System.exit(0);
 }
 });
 
 //frame.setContentPane(new ComboBoxDemo2());
 //frame.pack();
 //frame.setVisible(true);
}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/1/2004 6:40:47 PMDon Roberts

Where's the .gif files?
(If this comment was disrespectful, please report it.)

 
2/8/2009 8:56:39 AMankur

sir, plz if you can tell me what's the logic/idea for this kind of application as we already have as MS word, what new ideas/additions have you incorporated in it, and also wanting to know can this program can be used as a minor project for engg. degree.
thank you
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.