Results 1 to 3 of 3

Thread: puja

  1. #1
    puja is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default puja

    hiiiiiiiii..................i have make a notepad like application project.....all the project works properly....but now i have to add scrollbars,toolbars and ruler or slider in it.....so not getting how to add them.....so i request u to plzzzz do help me..........my code is as follows:


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.*;
    import java.io.*;
    import java.lang.String;
    import javax.swing.text.*;
    import javax.swing.undo.*;
    import java.awt.print.*;
    import java.util.GregorianCalendar;
    import java.util.*;
    import java.awt.Graphics;
    class major extends Frame implements ActionListener,ItemListener,Serializable,Clipboard Owner
    {
    String str=null;
    // Graphics symbols=str;
    static TextArea txa1;

    String sttr;


    protected UndoManager undo = new UndoManager();

    Font fnt1=new Font("Arial",Font.BOLD,14);
    Font fnt2=new Font("Roman",Font.BOLD,12);
    Font fnt3=new Font("Times New Roman",Font.ITALIC,13);
    Font fnt4=new Font("Lucida Sans Unicode",Font.ITALIC,15);
    Font fnt5=new Font("Lucida Console",Font.ITALIC+Font.BOLD,14);
    CheckboxMenuItem cb1,cb2,cb3,cb4,cb5;
    CheckboxMenuItem cf1,cf2,cf3,cf4,cf5;
    MenuItem mf2;

    Clipboard clipbd = getToolkit().getSystemClipboard();

    PrinterJob printerJob;
    PageFormat pageFormat;


    String filename=null;

    int x;

    public major()
    {



    txa1=new TextArea(null,40,12);//


    MenuBar mb=new MenuBar();

    Menu mf=new Menu("File");
    Menu me=new Menu("Edit");
    Menu mfo=new Menu("Format");
    Menu mh=new Menu("Help");
    MenuShortcut ms1=new MenuShortcut(KeyEvent.VK_N);
    MenuItem mf1=new MenuItem("New",ms1);
    mf1.addActionListener(this);
    MenuShortcut mns1=new MenuShortcut(KeyEvent.VK_O);
    mf2=new MenuItem("Open",mns1);
    mf2.addActionListener(new Open());
    MenuShortcut mns12=new MenuShortcut(KeyEvent.VK_S);
    MenuItem mf3=new MenuItem("Save",mns12);
    mf3.addActionListener(new Save());
    MenuItem mf4=new MenuItem("Save....As");
    mf4.addActionListener(new Save());
    MenuShortcut ccna=new MenuShortcut(KeyEvent.VK_1);
    MenuItem mf44=new MenuItem("Close",ccna);
    mf44.addActionListener(this);
    MenuShortcut prnt=new MenuShortcut(KeyEvent.VK_U);
    MenuShortcut setup=new MenuShortcut(KeyEvent.VK_P);
    MenuItem mf5=new MenuItem("Page Setup",setup);
    MenuItem mf6=new MenuItem("Print",prnt);
    mf6.addActionListener(this);
    mf5.addActionListener(this);
    MenuShortcut ext=new MenuShortcut(KeyEvent.VK_Q);

    MenuItem mf7=new MenuItem("Exit",ext);
    mf7.addActionListener(this);

    MenuShortcut mns2=new MenuShortcut(KeyEvent.VK_Z);
    MenuItem me1=new MenuItem("Undo",mns2);
    me1.addActionListener(new undo());

    MenuShortcut mns3=new MenuShortcut(KeyEvent.VK_X);
    MenuItem me2=new MenuItem("cut",mns3);
    me2.addActionListener(new cut());

    MenuShortcut mns4=new MenuShortcut(KeyEvent.VK_C);
    MenuItem me3=new MenuItem("Copy",mns4);
    me3.addActionListener(new copy());

    MenuShortcut mns5=new MenuShortcut(KeyEvent.VK_V);
    MenuItem me4=new MenuItem("Past",mns5);
    me4.addActionListener(new paste());

    MenuShortcut mns6=new MenuShortcut(KeyEvent.VK_D);
    MenuItem me5=new MenuItem("Delete",mns6);
    me5.addActionListener(new delete());

    /*MenuItem me6=new MenuItem("Fine...",mns6);
    MenuItem me7=new MenuItem("Find Next.. F3");

    MenuShortcut mns7=new MenuShortcut(KeyEvent.VK_F1);
    MenuItem me8=new MenuItem("Replace...",mns7);

    MenuShortcut mns8=new MenuShortcut(07);
    MenuItem me9=new MenuItem("Go To...",mns8);


    MenuShortcut dat_sh=new MenuShortcut(KeyEvent.VK_F5);*/
    MenuShortcut mns9=new MenuShortcut(KeyEvent.VK_A);
    MenuItem me10=new MenuItem("Select All",mns9);
    //MenuItem me11=new MenuItem("Date / Time ",dat_sh);
    me10.addActionListener(this);
    // me11.addActionListener(this);

    MenuItem mfo1=new MenuItem("BackGround");
    mfo1.addActionListener(this);
    mfo.add(mfo1);

    MenuItem mfo2=new MenuItem("TextColor");
    MenuItem fnfn=new MenuItem("Font");
    fnfn.addActionListener(this);
    mfo2.addActionListener(this);
    mfo.add(mfo2);
    mfo.add(fnfn);

    Menu mfo3=new Menu("Change Font");
    mfo.add(mfo3);
    mfo3.add(cf1=new CheckboxMenuItem("Arial"));
    mfo3.add(cf2=new CheckboxMenuItem("Roman"));
    mfo3.add(cf3=new CheckboxMenuItem("Times New Roman"));
    mfo3.add(cf4=new CheckboxMenuItem("Lucida Sans Unicode"));
    mfo3.add(cf5=new CheckboxMenuItem("Lucida Consol"));
    cf1.addItemListener(this);
    cf2.addItemListener(this);
    cf3.addItemListener(this);
    cf4.addItemListener(this);
    cf5.addItemListener(this);



    mfo.addSeparator();
    //11/03/2012


    MenuItem mh1=new MenuItem("Readme");
    mh1.addActionListener(this);
    MenuItem mh2=new MenuItem("About MiniWord");
    mh2.addActionListener(this);

    setMenuBar(mb);
    add(txa1);
    mb.add(mf);
    mb.add(me);
    mb.add(mfo);
    mb.setHelpMenu(mh);

    mf.add(mf1);
    mf.add(mf2);
    mf.addSeparator();
    mf.add(mf3);
    mf.add(mf4);
    mf.addSeparator();
    mf.add(mf44);
    mf.addSeparator();
    mf.add(mf5);
    mf.add(mf6);
    mf.addSeparator();
    mf.add(mf7);

    //11/03/2012
    me.add(me1);
    me.addSeparator();
    me.add(me2);
    me.add(me3);
    me.add(me4);
    me.add(me5);
    me.addSeparator();
    // me.add(me6);
    // me.add(me7);
    // me.add(me8);
    // me.add(me9);
    me.addSeparator();
    me.add(me10);
    // me.add(me11);


    mh.add(mh1);
    mh.add(mh2);


    }
    public void itemStateChanged(ItemEvent ie)
    {
    Object obj=ie.getItem();
    if (obj=="Arial")
    {
    cf2.setState(false);
    cf3.setState(false);
    cf4.setState(false);
    cf5.setState(false);
    txa1.setFont(fnt1);
    }
    if (obj=="Roman")
    {
    cf1.setState(false);
    cf3.setState(false);
    cf4.setState(false);
    cf5.setState(false);
    txa1.setFont(fnt2);
    }
    if (obj=="Times New Roman")
    {
    cf1.setState(false);
    cf2.setState(false);
    cf4.setState(false);
    cf5.setState(false);
    txa1.setFont(fnt3);
    }
    if (obj=="Lucida Sans Unicode")
    {
    cf1.setState(false);
    cf2.setState(false);
    cf3.setState(false);
    cf5.setState(false);
    txa1.setFont(fnt4);
    }
    if (obj=="Lucida Consol")
    {
    cf1.setState(false);
    cf2.setState(false);
    cf3.setState(false);
    cf4.setState(false);
    txa1.setFont(fnt5);
    }
    }

    public void actionPerformed(ActionEvent ae)
    {
    String msg=ae.getActionCommand();
    Object obj=new Object();
    obj=ae.getSource();

    if (msg.equals("New"))
    {
    txa1.setVisible(true);
    txa1.setText("");
    setTitle("Untitled MiniWord");
    }
    if (msg.equals("Print"))
    {
    onPrint();

    }
    if (msg.equals("Page Setup"))
    {
    OnPageSetup();
    }
    if(msg.equals("Open"))
    {

    FileDialog fd=new FileDialog(major.this,"Open",FileDialog.LOAD);
    fd.setVisible(true);
    String strd=null;
    String strf=null;
    String path=null;
    //String source=t1.getText();
    //System.out.println(source);
    if ((fd.getFile())!=null)
    {
    strd=fd.getDirectory();
    strf=fd.getFile();
    path=strd+strf;

    try
    {
    FileInputStream finput=new FileInputStream(path);
    int numberOfBytes=finput.available();
    byte inBuff[]=new byte[numberOfBytes];
    int readByte=finput.read(inBuff,0,numberOfBytes);
    String setstr=new String (inBuff);
    txa1.setVisible(true);
    txa1.setText("");
    txa1.setText(setstr);

    finput.close();
    }
    catch(FileNotFoundException fltex1)
    {
    System.out.println(fltex1);



    }
    catch(IOException fltex2)
    {
    //mesg="File Not Exist or not found";


    System.out.println(fltex2);
    }
    catch(Exception fltex3)
    {
    System.out.println(fltex3);
    }
    if ((fd.getFile())!=null)
    {
    setTitle("MiniWord-["+path+"]");
    }

    }


    }
    if (msg.equals("Save"))
    {
    new Save();
    }
    if (msg.equals("Save....As"))
    {
    new Save();

    }

    if (msg.equals("Close"))
    {
    txa1.setVisible(false);
    setTitle("MiniWord");

    }
    if (msg.equals("Exit"))
    {
    System.exit(0);

    }
    if (msg.equals("Select All"))
    {
    txa1.selectAll();
    }

    if (msg.equals("TextColor"))
    {
    Color color = JColorChooser.showDialog(major.this, "Color Chooser",Color.white);
    txa1.setForeground(color);
    }
    if (msg.equals("Font"))
    {
    new font1();

    }

    if (msg.equals("BackGround"))
    {
    Color color = JColorChooser.showDialog(major.this, "Color Chooser",Color.cyan);
    txa1.setBackground(color);
    }


    if (msg.equals("Readme"))
    {
    Help sttf = new Help("README", "README.txt");
    sttf.setResizable(false);
    // sttf.setMenimizable(false);
    sttf.setSize(600,400);
    }
    if (msg.equals("About MiniWord"))
    {
    JOptionPane.showMessageDialog(major.this,"THIS VERSION 1.0 OF MiniWord\nDeveloped by Prashant Thombre & Tanvi Tare\nVersion 1.1 will be uploaded soon\nThanks for \nTrying this software ","About MiniWord",JOptionPane.INFORMATION_MESSAGE);

    /*di.setSize(300,100);
    di.setVisible(true);
    di.setTitle("About MiniWord");
    l1.setText("This is version 1.0 of MiniWord ");*/

    }

    }
    public void lostOwnership(Clipboard clipboard, Transferable contents)
    {
    JOptionPane.showMessageDialog(major.this,"Clip board Contents Replaced","Clip Bord",JOptionPane.INFORMATION_MESSAGE);
    // System.out.println("Clipboard contents replaced");
    }


    class Open implements ActionListener
    {
    public void actionPerformed(ActionEvent ae)
    {


    FileDialog fd=new FileDialog(major.this,"Save File",FileDialog.LOAD);
    fd.setVisible(true);
    String strd=null;
    String strf=null;
    String path=null;
    //String source=t1.getText();
    //System.out.println(source);
    if ((fd.getFile())!=null)
    {
    strd=fd.getDirectory();
    strf=fd.getFile();
    path=strd+strf;

    try
    {
    FileInputStream finput=new FileInputStream(path);
    int numberOfBytes=finput.available();
    byte inBuff[]=new byte[numberOfBytes];
    int readByte=finput.read(inBuff,0,numberOfBytes);
    String setstr=new String (inBuff);
    txa1.setVisible(true);
    txa1.setText("");
    txa1.setText(setstr);

    finput.close();
    }
    catch(FileNotFoundException fltex1)
    {
    sttr=fltex1.toString();
    JOptionPane.showMessageDialog(major.this,sttr,"Err or",JOptionPane.INFORMATION_MESSAGE);
    //System.out.println(fltex1);

    setTitle("MiniWord");


    }
    catch(IOException fltex2)
    {

    //mesg="File Not Exist or not found";

    System.out.println(fltex2);
    }
    catch(Exception fltex3)
    {
    System.out.println(fltex3);
    }
    if ((fd.getFile())!=null)
    {
    setTitle("MiniWord-["+path+"]");
    }
    }
    }
    }
    //save start
    class Save implements ActionListener
    {
    public void actionPerformed(ActionEvent ae)
    {
    FileDialog fd=new FileDialog(major.this,"Save File",FileDialog.SAVE);
    fd.setVisible(true);
    String strd=fd.getDirectory();
    String strf=fd.getFile();
    String path=strd+strf;
    String source=txa1.getText();
    try
    {
    //String source="";
    char buffer[]=new char[source.length()];
    source.getChars(0,source.length(),buffer,0);
    FileWriter fo=new FileWriter(path);
    for (int i=0;i<buffer.length;i++)
    {
    fo.write(buffer[i]);
    }
    fo.close();
    }
    catch(FileNotFoundException fltex1)
    {
    System.out.println(fltex1);
    }
    catch(IOException fltex2)
    {
    System.out.println(fltex2);
    }
    catch(Exception fle3)
    {
    System.out.println(fle3);
    }


    txa1.requestFocus();
    setTitle("MiniWord-["+path+"]");
    }
    }
    //save end
    //font class
    class font1 implements ActionListener
    {
    JDialog fontDialog;
    JPanel p1;
    JButton ok,apply,cancel;
    Choice font;
    Choice fst;

    GraphicsEnvironment ge;
    String name[];
    String fsname[]={"Font.BOLD","Font.ITALIC","Font.PLAIN"};
    TextField tx;
    Font fnt;
    //public Hashtable styles = new Hashtable();
    //styles.put( new Integer(Font.PLAIN));
    // styles.put("Bold", new Integer(Font.BOLD));
    // styles.put("Italic", new Integer(Font.ITALIC));
    // styles.put("Bold Italic", new Integer(Font.BOLD | Font.ITALIC));

    int i=0;
    font1()
    {


    fontDialot=new JDialog(major.this);
    p1=new JPanel();
    ok=new JButton("OK");
    apply=new JButton("Apply");
    cancel=new JButton("Cancel");
    tx=new TextField("13",14);
    font=new Choice();
    fst=new Choice();
    ge=GraphicsEnvironment.getLocalGraphicsEnvironment ();
    name=ge.getAvailableFontFamilyNames();
    fontDialot.getContentPane().add(p1);
    p1.add(font);
    p1.add(tx);
    p1.add(fst);
    p1.add(ok);
    p1.add(apply);
    p1.add(cancel);
    apply.addActionListener(new apply_font());
    cancel.addActionListener(new cancel1());

    ok.addActionListener(this);
    for(int x=0;x<name.length;x++)
    {
    font.addItem(name[x]);
    }
    for (int y=0;y!=3;y++ )
    {
    fst.addItem(fsname[y]);
    }

    fontDialot.setVisible(true);
    fontDialot.setSize(400,400);
    }
    public void actionPerformed(ActionEvent ae)
    {

    String s=font.getSelectedItem();
    String sz=tx.getText();
    String styl=fst.getSelectedItem();


    int size=Integer.parseInt(sz);
    fnt=new Font(s,Font.PLAIN,size);
    //System.out.println("JLKJLKS");
    major.txa1.setFont(fnt);
    fontDialot.dispose();

    }
    class apply_font implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String s=font.getSelectedItem();
    String sz=tx.getText();
    String styl=fst.getSelectedItem();
    int size=Integer.parseInt(sz);

    fnt=new Font(s,Font.PLAIN,size);

    try
    {
    major.txa1.setFont(fnt);
    }
    catch (Exception e1)
    {
    System.out.println(e1);
    }
    }
    }
    class cancel1 implements ActionListener
    {
    public void actionPerformed(ActionEvent ae)
    {
    fontDialot.dispose();
    }
    }
    }

    //end font class
    class cut implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String selection = txa1.getSelectedText();
    if (selection == null)
    return;
    StringSelection clipString =
    new StringSelection(selection);
    clipbd.setContents(clipString, clipString);
    txa1.replaceRange("", txa1.getSelectionStart(),txa1.getSelectionEnd());
    }
    }
    class copy implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String selection = txa1.getSelectedText();
    if (selection == null)
    return;
    StringSelection clipString =new StringSelection(selection);
    clipbd.setContents(clipString,clipString);
    }

    }
    class delete implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String selection = txa1.getSelectedText();
    if (selection == null)
    return;
    StringSelection clipString =new StringSelection(selection);
    clipbd.setContents(clipString,clipString);
    }

    }
    class undo implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String selection = txa1.getSelectedText();
    if (selection == null)
    return;
    StringSelection clipString =new StringSelection(selection);
    clipbd.setContents(clipString,clipString);
    }

    }
    class paste implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    Transferable clipData =
    clipbd.getContents(major.this);
    try
    {
    String clipString =
    (String)clipData.getTransferData(DataFlavor.string Flavor);
    txa1.replaceRange(clipString,txa1.getSelectionStar t(),txa1.getSelectionEnd());
    }
    catch(Exception evt)
    {
    System.out.println("not String flavor");
    }
    }
    }
    //.help class

    class Help extends JFrame
    {
    public Help(String title, String filename)
    {
    super(title);
    TextArea ta = new TextArea(24, 80);
    ta.setEditable(false);
    String text = "";
    String holdString;
    try
    {
    BufferedReader in = new BufferedReader(new FileReader(filename));

    while ((holdString = in.readLine()) != null)
    {
    text += holdString + "\n";
    }

    in.close();

    ta.setText(text);
    getContentPane().add("Center", ta);
    pack();
    show();

    }
    catch (java.io.IOException ioe)
    {
    JOptionPane.showMessageDialog(major.this,"Error while reading file:_"+filename,"Error",JOptionPane.ERROR_MESSAGE );
    //System.err.println("Error reading text from file: " + filename);
    }
    }
    }


    // \help class




    public static void main(String[] args)
    {
    Frame f1=new major();
    f1.addWindowListener(new close());
    f1.setSize(500,500);
    f1.show();

    }

    public void OnPageSetup()//the page setup method
    {
    if (printerJob == null)
    {
    printerJob = PrinterJob.getPrinterJob();
    }
    if (pageFormat == null)
    {
    pageFormat = printerJob.defaultPage();
    }

    pageFormat = printerJob.pageDialog(pageFormat);
    }
    //the prin method here

    public void onPrint()
    {

    if (printerJob == null)
    {
    printerJob = PrinterJob.getPrinterJob();
    }
    if (pageFormat == null)
    {
    pageFormat = printerJob.defaultPage();
    }
    // printerJob.setPrintable(ta,pageFormat);

    if (printerJob.printDialog())
    {
    try
    {
    printerJob.print();
    }
    catch (PrinterException pe)
    {
    System.err.println(pe);
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(major.this,"Error in print method","Error",JOptionPane.ERROR_MESSAGE);
    }
    }
    printerJob = null;
    }
    //the print end


    }

    class close extends WindowAdapter
    {
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: puja

    1. Go through the forum FAQs and learn how to post code so that it retains its formatting.
    2. Apply the shift key on your keyboard for the first letter of each sentence and the first person singular "I"
    3. Don't hold down keys and repeat letters or periods. That makes your post difficult to read and annoying.
    4. Spell words the way they ought to be. 'Please' is a word, 'plzzzz' is not.
    5. Use a meaningful subject line. Your username isn't one.
    6. Post less code, in the form of an SSCCE, and ask a specific question.

    Have you gone through the Tutorial Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials) ?

    Other recommended reading: How to ask questions the smart way

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: puja

    Moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •