Results 1 to 4 of 4
  1. #1
    ronnie is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default writing full program in one class only

    //calling class
    import javax.swing.JFrame;
    class jcheckkbox {
    public static void main(String args[]) {
    jRadio roof = new jRadio();
    roof.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    roof.setSize(300, 200);
    roof.setVisible(true);



    //secondary class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;



    public class jcheckbox extends JFrame {
    private JCheckBox cd;
    private JCheckBox md;
    private JTextField vcd;

    public jcheckbox() {
    super("Beer bar");
    setLayout(new FlowLayout());

    vcd = new JTextField("this is a code", 20);
    vcd.setFont(new Font("Serif", Font.PLAIN, 22));
    vcd.setToolTipText("yahoo");
    add(vcd);

    cd = new JCheckBox("bold");
    md = new JCheckBox("italic");
    add(md);
    add(cd);

    handler dahandler = new handler();
    cd.addItemListener(dahandler);
    md.addItemListener(dahandler);

    }
    private class handler implements ItemListener {
    public void itemStateChanged(ItemEvent event) {
    Font cool = null;
    if (md.isSelected() && cd.isSelected())
    cool = new Font("Serif", Font.BOLD + Font.ITALIC, 25);
    else if (md.isSelected())
    cool = new Font("Serif", Font.BOLD, 30);
    else if (md.isSelected())
    cool = new Font("Sans_Serif", Font.ITALIC, 30);

    vcd.setFont(cool);

    }}}

    how to write a program in just one class i mean no need calling class for setsize or defaultcloseoperation etc because two classes are harder to compile when making a .jar or .exe out of it,i know there is another way but i want to use this method as it is a lot more easier to make buttons,textfields comboboxes with this method
    Last edited by ronnie; 03-25-2012 at 03:33 PM. Reason: modification

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: writing full program in one class only

    Quote Originally Posted by ronnie View Post
    how to write a program in just one class i mean no need calling class for setsize or defaultcloseoperation etc because two classes are harder to compile when making a .jar or .exe out of it,i know there is another way but i want to use this method as it is a lot more easier to make buttons,textfields comboboxes with this method

    Sorry, but this doesn't make sense to me. Whether or not you have one or many classes has no bearing on whether you need to set sizes or set the default close operation, and adds little complexity to creating a jar. The rest of your post makes less sense to me. please clarify and ask a specific question if you have one.

  3. #3
    ronnie is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: writing full program in one class only

    so can you guide me how to create jar file with two classes in hand,there are tutorials out there but all are making jar with only one class

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: writing full program in one class only

    Quote Originally Posted by ronnie View Post
    so can you guide me how to create jar file with two classes in hand,there are tutorials out there but all are making jar with only one class
    To create a Jar file with more than one class file when using the jar cf command, simply state all the files that need to be added with a space between each file after the jar file name. It's all spelled out here: Creating a Jar File

Similar Threads

  1. Help with writing my own program
    By DMarsh12 in forum New To Java
    Replies: 4
    Last Post: 12-30-2011, 03:34 AM
  2. run last class in full size window
    By sonny in forum Eclipse
    Replies: 0
    Last Post: 03-05-2010, 02:56 PM
  3. Due Tommorow Writing a Program Please Help
    By gallimaufry in forum New To Java
    Replies: 4
    Last Post: 10-23-2008, 03:15 AM
  4. [SOLVED] open a program full size
    By keffie91 in forum Advanced Java
    Replies: 2
    Last Post: 10-05-2008, 10:26 AM
  5. how begin with writing a new program ?
    By dimitrist in forum New To Java
    Replies: 11
    Last Post: 05-13-2008, 03:49 AM

Tags for this Thread

Posting Permissions

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