⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontdialog.java

📁 本人总结记事本的多种功能为一体,自己做了一个很全面的与大家分亨
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;

public class FontDialog extends JDialog implements ActionListener
{    
     JLabel lfont=new JLabel("字体",JLabel.CENTER);
     
     JLabel lsize=new JLabel("字号",JLabel.CENTER);
     
     JLabel lcolor=new JLabel("颜色",JLabel.CENTER);
     
     JButton ccolor=new JButton("选取颜色");
     
     JButton sure=new JButton("确定");
     
     JButton cancel=new JButton("取消");	
     
     JComboBox cfont=new JComboBox();
     
     JComboBox csize=new JComboBox();
      
     Color color = Color.BLACK; 

	 String ffont =  "宋体";

	 int fsize = 16; 

     
  public FontDialog(MyNotePad superWindow) 
   {
      super(superWindow, "字体设置", true);
      
      JPanel c =  (JPanel) this.getContentPane();

		c.setLayout(new GridLayout(4, 2, 3, 8));
		
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	     
	    String[] fonts = ge.getAvailableFontFamilyNames();
	     
	    DefaultComboBoxModel fontModel = new DefaultComboBoxModel(fonts);
		
		     cfont.setModel(fontModel);
		
		int[] sizes = new int[30];
		
		String[] strSizes = new String[30];

	    for (int i = 0; i < 30; i++) 
	    {
            sizes[i] = 16 + i * 2;

            strSizes[i] = String.valueOf(sizes[i]);
			
		}
		
		DefaultComboBoxModel sizeModel = new DefaultComboBoxModel(strSizes);
		
		     csize.setModel(sizeModel);
		     
		
		ccolor.addActionListener(new ActionListener(){
       	   public void actionPerformed(ActionEvent e){
       	       color=JColorChooser.showDialog(FontDialog.this,"选取颜色",Color.BLACK);}});
        
        sure.addActionListener(this);
        
        cancel.addActionListener(this);
         
        c.add(lfont);
        c.add(cfont);
        
        c.add(lsize);
        c.add(csize);
        
        c.add(lcolor);
        c.add(ccolor);
        
        c.add(sure);
        c.add(cancel);
        
        this.setBounds(100,200,200,160);
         
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        
     }
 
    public void actionPerformed(ActionEvent e)
    {
   	  if(e.getSource()==sure)
   	  {
   	  	  ffont=(String)cfont.getSelectedItem();
   	           
   	      fsize=Integer.parseInt((String)csize.getSelectedItem());
   	  	      
   	  	  this.dispose();
   	  } 
   	  
   	  if(e.getSource()==cancel)
   	  {
   	  	   Color color = Color.BLACK;
             
           String ffont =  "宋体";
             
           int fsize = 16; 
   	  	     
   	  	   FontDialog.this.dispose();
   	  }
    }
  
    public Color getColor() {

		return color;
	}

	public String getFontName(){
		
		return ffont;
	}
	
	public int getFontSize(){
		
		return fsize;
	} 
	
}

 
 
 
 
 
  
        
       
       	       
       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -