Announcement

Collapse
No announcement yet.

Real Time Font Changer - GUI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • xgiovio
    replied
    Package FontChange

    Class CenterPanel
    PHP Code:
    package FontChange;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:30
     */
    public class CenterPanel {


        public 
    CenterPanel (MainFrame in_up) {


            
    = new JLabel("Big Giovio");

            
    panel = new JPanel();
            
    panel.add(l);

        }

        public 
    JPanel getp (){
            return 
    panel;
        }


        public 
    void rewrite (Font in_f){
            
    l.setFont(in_f);
            
    l.repaint();
        }



        private 
    JPanel panel;
        private 
    JLabel l;



    Class MainFrame

    PHP Code:
    package FontChange;

    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.*;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:14
     */
    public class MainFrame extends JFrame {

        public 
    MainFrame (int in_wint in_h ){

            
    w=in_w;
            
    h=in_h;

            
    setSize(w,h);
            
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            
    JPanel main_p = new JPanel(new BorderLayout());
            
    main_p.setBorder(new TitledBorder(new EtchedBorder(),"RealTime Font Changer"));
            
    add(main_p);

            
    center_p = new CenterPanel(this);
            
    south_p = new SouthPanel(this);

            
    main_p.add(center_p.getp(),BorderLayout.CENTER);
            
    main_p.add(south_p.getp(),BorderLayout.SOUTH);

            
    center_p.rewrite(new Font("sansserif",0,20));
            
    setVisible(true);

        }

        public 
    CenterPanel getCenter_p() {
            return 
    center_p;
        }

        public 
    SouthPanel getSouth_p() {
            return 
    south_p;
        }

        private 
    CenterPanel center_p ;
        private 
    SouthPanel south_p ;

        private 
    int w;
        private 
    int h;


    Class ReWriteListner

    PHP Code:
    package FontChange;

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 19:18
     */
    class ReWriteListner implements ActionListener {

        public 
    ReWriteListnerMainFrame in_up){
            
    up in_up;
        }

        @
    Override
        
    public void actionPerformed(ActionEvent e) {

            
    String a;

            if (((String)(
    up.getSouth_p().getPfont().getCombo().getSelectedItem())).equals("sansserif")){
                
    "sansserif";
            } else {
                
    "monospaced";
            }
            
    int b 0;

            if (
    up.getSouth_p().getPstyle().getBold().isSelected()){
                
    b+= Font.BOLD;
            }

            if (
    up.getSouth_p().getPstyle().getItalic().isSelected()){
                
    b+= Font.ITALIC;
            }


            
    int c;

            if ( 
    up.getSouth_p().getPsize().getS().isSelected()  ){
                
    c10;
            } else {
                if ( 
    up.getSouth_p().getPsize().getM().isSelected()  ){
                    
    c20;
                } else {
                    
    30;
                }

            }


            
    Font f = new Font(a,b,c);
            
    up.getCenter_p().rewrite(f);




        }
        private 
    MainFrame up;

    Class SouthPanel
    PHP Code:
    package FontChange;

    import javax.swing.*;
    import java.awt.*;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:30
     */
    public class SouthPanel {


        public 
    SouthPanelMainFrame up) {

            
    panel = new JPanel(new GridLayout(3,1));

            
    pfont = new SouthPanelFont(up);
            
    pstyle = new SouthPanelStyle(up);
            
    psize = new SouthPanelSize(up);

            
    panel.add(pfont.getp());
            
    panel.add(pstyle.getp());
            
    panel.add(psize.getp());

        }

        public 
    JPanel getp (){
            return 
    panel;
        }

        public 
    SouthPanelFont getPfont() {
            return 
    pfont;
        }

        public 
    SouthPanelSize getPsize() {
            return 
    psize;
        }

        public 
    SouthPanelStyle getPstyle() {
            return 
    pstyle;
        }

        private 
    JPanel panel;
        private 
    SouthPanelFont pfont;
        private 
    SouthPanelSize psize;
        private 
    SouthPanelStyle pstyle;



    Class SouthPanelFont
    PHP Code:
    package FontChange;

    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.*;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:30
     */
    public class SouthPanelFont {


        public 
    SouthPanelFontMainFrame up) {

            
    panel = new JPanel();
            
    panel.setBorder(new TitledBorder(new EtchedBorder(),"Font"));

            
    combo = new JComboBox<String>();
            
    combo.addItem("sansserif");
            
    combo.addItem("monospaced");

            
    panel.add(combo);

            
    combo.addActionListener(new ReWriteListner(up));




        }

        public 
    JPanel getp (){
            return 
    panel;
        }

        public 
    JComboBox<StringgetCombo() {
            return 
    combo;
        }

        private 
    JPanel panel;
        private 
    JComboBox <Stringcombo;



    Class SouthPanelSize
    PHP Code:
    package FontChange;

    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.*;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:30
     */
    public class SouthPanelSize {


        public 
    SouthPanelSizeMainFrame up) {

            
    panel = new JPanel();
            
    panel.setBorder(new TitledBorder(new EtchedBorder(),"Size"));



            
    = new ButtonGroup();

            
    s= new JRadioButton("Small");
            
    m= new JRadioButton("Medium");
            
    l= new JRadioButton("Large");

            
    s.addActionListener(new ReWriteListner(up));
            
    m.addActionListener(new ReWriteListner(up));
            
    l.addActionListener(new ReWriteListner(up));

            
    m.setSelected(true);

            
    g.add(s);
            
    g.add(m);
            
    g.add(l);

            
    panel.add(s);
            
    panel.add(m);
            
    panel.add(l);

        }

        public 
    JPanel getp (){
            return 
    panel;
        }

        public 
    JRadioButton getS() {
            return 
    s;
        }

        public 
    JRadioButton getM() {
            return 
    m;
        }

        public 
    JRadioButton getL() {
            return 
    l;
        }

        private 
    JPanel panel;
        private 
    ButtonGroup g;
        private 
    JRadioButton s;
        private 
    JRadioButton m;
        private 
    JRadioButton l;




    Class SouthPanelStyle
    PHP Code:
    package FontChange;

    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.*;

    /**
     * Created with xgiovio.macbookair.
     * User: xgiovio
     * Date: 10/12/13
     * Time: 17:30
     */
    public class SouthPanelStyle {


        public 
    SouthPanelStyleMainFrame up)  {

            
    panel = new JPanel();
            
    panel.setBorder(new TitledBorder(new EtchedBorder(),"Style"));


            
    bold = new JCheckBox("Bold");
            
    italic = new JCheckBox("Italic");




            
    panel.add(bold);
            
    panel.add(italic);


            
    bold.addActionListener(new ReWriteListner(up));
            
    italic.addActionListener(new ReWriteListner(up));


        }

        public 
    JPanel getp (){
            return 
    panel;
        }



        public 
    JCheckBox getBold() {
            return 
    bold;
        }

        public 
    JCheckBox getItalic() {
            return 
    italic;
        }

        private 
    JPanel panel;
        private 
    JCheckBox bold;
        private 
    JCheckBox italic;




    Leave a comment:


  • xgiovio
    replied
    main
    PHP Code:
    import FontChange.MainFrame;


    public class 
    test {

        public static 
    void main (String [] input_data) {

            
    MainFrame f = new MainFrame(300,300);


        }

    Leave a comment:


  • xgiovio
    started a topic Real Time Font Changer - GUI

    Real Time Font Changer - GUI

    Click image for larger version

Name:	big_giovio.png
Views:	693
Size:	19.1 KB
ID:	454
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia