Announcement
Collapse
No announcement yet.
Real Time Font Changer - GUI
Collapse
X
-
Real Time Font Changer - GUI
| VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio Tags: None
-
main
PHP Code:import FontChange.MainFrame;
public class test {
public static void main (String [] input_data) {
MainFrame f = new MainFrame(300,300);
}
}
| VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
-
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) {
l = 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;
}
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_w, int 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;
}
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 ReWriteListner( MainFrame in_up){
up = in_up;
}
@Override
public void actionPerformed(ActionEvent e) {
String a;
if (((String)(up.getSouth_p().getPfont().getCombo().getSelectedItem())).equals("sansserif")){
a = "sansserif";
} else {
a = "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() ){
c= 10;
} else {
if ( up.getSouth_p().getPsize().getM().isSelected() ){
c= 20;
} else {
c = 30;
}
}
Font f = new Font(a,b,c);
up.getCenter_p().rewrite(f);
}
private MainFrame up;
}
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 SouthPanel( MainFrame 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;
}
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 SouthPanelFont( MainFrame 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<String> getCombo() {
return combo;
}
private JPanel panel;
private JComboBox <String> combo;
}
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 SouthPanelSize( MainFrame up) {
panel = new JPanel();
panel.setBorder(new TitledBorder(new EtchedBorder(),"Size"));
g = 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;
}
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 SouthPanelStyle( MainFrame 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;
}
| VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Comment
Comment