欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

GUI中文乱码解决

程序员文章站 2024-01-27 08:40:58
...
//创建主题样式,避免中文乱码
  StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    // 设置标题字体
  standardChartTheme.setExtraLargeFont(new Font("宋体", Font.BOLD, 20));
    // 设置图例的字体
  standardChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));
    // 设置轴向的字体
  standardChartTheme.setLargeFont(new Font("宋体", Font.PLAIN, 15));
    // 应用主题样式
  ChartFactory.setChartTheme(standardChartTheme);

主体实例
 



3.  Integer [][]visitordata={{2004,1500},{2005,1450},{2006,2000},{2007,2050},{2008,2500},{2009,2000},{2010,1600},{2011,3000},{2012,3200},{2013,4000},{2014,3500},{2015,2000},{2016,2300}};
4.    String []title = {"年份","访问人数"};
5.    
6.    //显示数据到表格中
7.    DefaultTableModel model = new DefaultTableModel();
8.    model.setDataVector(visitordata, title);
9.    tablevisitor.setModel(model);
10.    
11.    //创建访问人数的图表
12.    DefaultCategoryDataset chart_dataset = new DefaultCategoryDataset();
13.    for(int i=0;i<12;i++)
14.    {
15.        chart_dataset.addValue(visitordata[i][1], "图书部访问人员统计数据", visitordata[i][0]);
16.    }
17.    
18.    JFreeChart lineChart = ChartFactory.createLineChart("图书馆访问人员统计表图","年份","访问人数",chart_dataset,PlotOrientation.VERTICAL, true, true, false);
19.    ChartPanel chartpanel = new ChartPanel(lineChart);
20.    chartpanel.setSize(panelChart.getSize());
21.    panelChart.removeAll();
22.    panelChart.add(chartpanel);
23.    panelChart.validate();
24.}


public CalculatorForm() {
        initComponents();
        lblOutput.setText("");
    }




1.private void AdditionButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
2.    // TODO add your handling code here:
3.    lblOutput.setText(Integer.toString(Integer.parseInt(txtNumber1.getText())
+Integer.parseInt(txtNumber2.getText())));
4.}
5.private void SubtractionButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
6.    // TODO add your handling code here:
7.    lblOutput.setText(Integer.toString(Integer.parseInt(txtNumber1.getText())-Integer.parseInt(txtNumber2.getText())));
8. }                                                 
9.private void MultiplicationButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                     
10.    // TODO add your handling code here:
11.    lblOutput.setText(Integer.toString(Integer.parseInt(txtNumber1.getText())
*Integer.parseInt(txtNumber2.getText())));
12.}                                                    
13.private void DivisionButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
14.    // TODO add your handling code here:
15.    lblOutput.setText(Integer.toString(Integer.parseInt(txtNumber1.getText())
/Integer.parseInt(txtNumber2.getText())));
16.}
17.private void ExponentialButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
18.    // TODO add your handling code here:
19.lblOutput.setText(Double.toString(Math.pow(Double.parseDouble(txtNumber1.getText()),
Double.parseDouble(txtNumber2.getText()))));
20.}




String Student[] = {"王宇东","黄智奇","岳泽宇","屈嘉尧","邓超","林一恒","刘新纪","肖佳乐","肖有坤","严立博"};
	double GPA[] = {3.38,3.0,2.98,3.01,2.87,3.4,2.9,3.0,2.9,2.9};
	
	public StudentForm() {
		initComponents();
		listStudent.setListData(Student);	//显示在列表中的学生姓名
	}
以下是列表的ValueChanged事件的代码。(StudentForm.java)
	private void listStudentValueChanged(javax.swing.event.ListSelectionEvent evt) {
        // T0D0 add your handling code here:
		int index = listStudent.getSelectedIndex();
		txtGPA.setText(GPA[index]+"");	//显示GPA
	}