Skip to content

Instantly share code, notes, and snippets.

@fsubal
Created August 19, 2013 14:48
Show Gist options
  • Save fsubal/6269950 to your computer and use it in GitHub Desktop.
Save fsubal/6269950 to your computer and use it in GitHub Desktop.
Ranking outputter for the manga exhibitions at my university. This is the old version.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.UIManager;
import javax.swing.JPanel;
import java.io.*;
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import java.io.File;
import javax.swing.filechooser.FileFilter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.lang.*;
import java.lang.String;
import java.lang.Comparable;
import java.lang.NumberFormatException;
import java.text.*;
import java.math.*;
public class Tabs extends JFrame implements ChangeListener,ActionListener{
/* タブ用のパネル */
JPanel settings = new JPanel();
JPanel input = new JPanel();
JPanel ranking = new JPanel();
JPanel table = new JPanel();
JPanel analyze = new JPanel();
/* 初期設定(settings)内パーツ */
JTextArea titles = new JTextArea();
JScrollPane titles2 = new JScrollPane(titles);
JButton setopen = new JButton("開く");
JButton setsave = new JButton("保存");
JLabel SettingsCaption = new JLabel("漫画のタイトルを1作品につき1行ずつ登録します。");
/* 入力(input)内パーツ */
JTextArea values = new JTextArea();
JScrollPane values2 = new JScrollPane(values);
JButton inputopen = new JButton("開く");
JButton inputsave = new JButton("保存");
JLabel InputCaption = new JLabel("アンケートの中身を、書いた人1人につき1行ずつ登録します。");
JLabel InputGuide = new JLabel("X(性別)X(職業) XX(作品番号)X(絵評価)X(話評価)");
/* 集計(ranking)内パーツ */
JPanel radiobox =new JPanel();
JPanel sortset =new JPanel();
JPanel out =new JPanel();
JLabel radio = new JLabel("作品番号");
JRadioButton zero = new JRadioButton("0始まり");
JRadioButton one = new JRadioButton("1始まり");
JLabel sortbycap = new JLabel("母集団 : ");
JLabel sexcap = new JLabel("性別");
JLabel occupationcap = new JLabel("職業");
String[] sexdata = {"指定なし", "男性", "女性"};
JComboBox sex = new JComboBox(sexdata);
String[] ocupationdata = {"指定なし", "小学生", "中学生","高校生","大学生","院生","社会人","その他","大学生+院生"};
JComboBox occupation = new JComboBox(ocupationdata);
String[] rankdata = {"得票数順", "絵評価順", "話評価順"};
JComboBox rankfor = new JComboBox(rankdata);
JButton rankbegin = new JButton("集計");
JTextArea ranked = new JTextArea();
JScrollPane ranked2 = new JScrollPane(ranked);
JButton ranksubmit = new JButton("保存");
/* 来訪者(table)内パーツ */
JLabel tablecap = new JLabel("来訪者数の集計を行います。");
JTextArea tablevalue = new JTextArea();
JScrollPane tablevalue2 = new JScrollPane(tablevalue);
JButton tableput = new JButton("集計");
JButton tablesubmit = new JButton("保存");
/* 詳細(analyze)内パーツ */
JLabel analyzecap = new JLabel("作品番号を入力してください。");
JTextField number = new JTextField();
JTextArea analyzed = new JTextArea();
JScrollPane analyzed2 = new JScrollPane(analyzed);
JTextArea analyzedtable = new JTextArea();
JScrollPane analyzedtable2 = new JScrollPane(analyzedtable);
JButton analyzeput = new JButton("分析");
JButton analyzesubmit = new JButton("点数保存");
JButton analyzetablesubmit = new JButton("表を保存");
Tabs() {
super("Tabs");
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add("初期設定", settings);
tabbedPane.add("入力", input);
tabbedPane.add("集計", ranking);
tabbedPane.add("来訪者", table);
tabbedPane.add("詳細", analyze);
tabbedPane.addChangeListener(this);
getContentPane().add(tabbedPane);
/* settingsタブの中身 */
settings.setLayout(new FlowLayout());
settings.add(titles2);
titles2.setPreferredSize(new Dimension(320, 240));
titles.setLineWrap(false);
settings.add(setopen);
setopen.setSize(20, 10);
setopen.addActionListener(this);
settings.add(setsave);
setsave.setSize(20, 10);
setsave.addActionListener(this);
settings.add(SettingsCaption);
/* inputタブの中身 */
input.setLayout(new FlowLayout());
input.add(values2);
values2.setPreferredSize(new Dimension(320, 240));
values.setLineWrap(false);
input.add(inputopen);
inputopen.setSize(20, 10);
inputopen.addActionListener(this);
input.add(inputsave);
inputsave.setSize(20, 10);
inputsave.addActionListener(this);
input.add(InputCaption);
input.add(InputGuide);
InputGuide.setFont(new Font("SansSerif", Font.BOLD, 16));
/* rankingタブの中身 */
ButtonGroup group = new ButtonGroup();
group.add(zero);
group.add(one);
ranking.setLayout(new FlowLayout());
ranking.add(radiobox);
ranking.add(sortset);
ranking.add(out);
/* 1段目 */
radiobox.setLayout(new FlowLayout());
radiobox.add(radio);
radiobox.add(zero);
zero.addActionListener(this);
radiobox.add(one);
one.addActionListener(this);
/* 2段目 */
sortset.setLayout(new FlowLayout());
sortset.add(sortbycap);
sortset.add(sexcap);
sortset.add(sex);
sortset.add(occupationcap);
sortset.add(occupation);
sortset.add(rankfor);
/* 3段目 */
out.setLayout(new FlowLayout());
out.add(ranked2);
ranked2.setPreferredSize(new Dimension(320, 200));
ranked.setLineWrap(false);
out.add(rankbegin);
rankbegin.addActionListener(this);
out.add(ranksubmit);
ranksubmit.addActionListener(this);
/* tableタブの中身 */
table.setLayout(new FlowLayout());
table.add(tablevalue2);
tablevalue2.setPreferredSize(new Dimension(320, 200));
tablevalue.setLineWrap(false);
table.add(tableput);
tableput.addActionListener(this);
table.add(tablesubmit);
tablesubmit.addActionListener(this);
table.add(tablecap);
/* analyzeタブの中身 */
analyze.setLayout(new FlowLayout());
analyze.add(analyzecap);
analyze.add(number);
number.setPreferredSize(new Dimension(120, 20));
analyze.add(analyzeput);
analyzeput.addActionListener(this);
analyze.add(analyzed2);
analyzed2.setPreferredSize(new Dimension(320, 120));
analyzed.setLineWrap(false);
analyze.add(analyzesubmit);
analyzesubmit.addActionListener(this);
analyze.add(analyzedtable2);
analyzedtable2.setPreferredSize(new Dimension(320, 120));
analyzedtable.setLineWrap(false);
analyze.add(analyzetablesubmit);
analyzetablesubmit.addActionListener(this);
/* ウィンドウ */
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Tsukushi Beta");
setSize(480,400);
setVisible(true);
}
/* ボタンの挙動 */
public void actionPerformed(ActionEvent e2) {
JFileChooser filechooser = new JFileChooser();
/*保存ボタン*/
if (e2.getSource() == setsave || e2.getSource() == inputsave || e2.getSource() == ranksubmit || e2.getSource() == tablesubmit || e2.getSource() == analyzesubmit || e2.getSource() == analyzetablesubmit){
/* SaveAs関数 */
int x = filechooser.showSaveDialog(this);
try {
if (x == JFileChooser.APPROVE_OPTION) {
if (e2.getSource()!=tablesubmit && e2.getSource()!=analyzetablesubmit) {
FileWriter fw = new FileWriter(filechooser.getSelectedFile() + ".txt");
int i=0;
String splited[] = new String[2000];
StringBuilder sb = new StringBuilder();
String crlf = System.getProperty("line.separator");
if (e2.getSource() == setsave)splited = titles.getText().split("\n");
else if (e2.getSource() == inputsave)splited = values.getText().split("\n");
else if (e2.getSource() == ranksubmit)splited = ranked.getText().split("\n");
else if (e2.getSource() == analyzesubmit)splited = analyzed.getText().split("\n");
for(i=0;i<splited.length;i++){
sb.append(splited[i]+crlf);
}
fw.flush();
fw.write(new String(sb));
System.out.println(new String(sb));
fw.close();
}else if(e2.getSource()==tablesubmit || e2.getSource()==analyzetablesubmit) {
FileWriter fw = new FileWriter(filechooser.getSelectedFile() + ".csv");
int i=0;
String splited[] = new String[2000];
StringBuilder sb = new StringBuilder();
String crlf = System.getProperty("line.separator");
if (e2.getSource() == tablesubmit)splited = tablevalue.getText().split("\n");
else if (e2.getSource() == analyzetablesubmit)splited = analyzedtable.getText().split("\n");
for(i=0;i<splited.length;i++){
sb.append(splited[i]+crlf);
}
fw.flush();
fw.write(new String(sb));
System.out.println(new String(sb));
fw.close();
}
}} catch(Exception ex) {
ex.printStackTrace();
}
}else
/*開くボタン*/
if (e2.getSource() == setopen || e2.getSource() == inputopen){
int selected = filechooser.showOpenDialog(this);
if (selected == JFileChooser.APPROVE_OPTION){
File file = filechooser.getSelectedFile();
/* タブによる分岐 */
if (e2.getSource() == setopen)titles.setText("");
if (e2.getSource() == inputopen)values.setText("");
try{
if (checkBeforeReadfile(file)){
BufferedReader br
= new BufferedReader(new FileReader(file));
String str;
String[] list = new String[2001];
int i=0;
while((str = br.readLine()) != null){
i++;
list[i]=str;
/* タブによる分岐 */
if (e2.getSource() == setopen){
titles.append(str);
titles.append("\n");
}else if(e2.getSource() == inputopen){
values.append(str);
values.append("\n");
}
}
br.close();
}else{
System.out.println("ファイルが見つからないか開けません");
}
}catch(FileNotFoundException err){
System.out.println(err);
}catch(IOException err){
System.out.println(err);
}
}
}else if(e2.getSource() == rankbegin){
/* 集計ボタン */
String[] lines = new String[2000];
lines = values.getText().split("\n");
/* 性別のみフィルタあり */
if(sex.getSelectedIndex()!=0&&occupation.getSelectedIndex()==0){
for(int i=0;i<lines.length;i++){
if(Integer.valueOf(lines[i].substring(0,1)).intValue()!=sex.getSelectedIndex())lines[i]="00";
}
}else if(sex.getSelectedIndex()==0&&occupation.getSelectedIndex()!=0){
/* 職業のみフィルタあり */
if(occupation.getSelectedIndex()!=8){
for(int i=0;i<lines.length;i++){
if(Integer.valueOf(lines[i].substring(1,2)).intValue()!=occupation.getSelectedIndex())lines[i]="00";
}}else if(occupation.getSelectedIndex()==8){
for(int i=0;i<lines.length;i++){
if(Integer.valueOf(lines[i].substring(1,2)).intValue()!=4&&Integer.valueOf(lines[i].substring(1,2)).intValue()!=5)lines[i]="00";
}}
}else if(sex.getSelectedIndex()!=0&&occupation.getSelectedIndex()!=0){
/* 両方フィルタあり */
if(occupation.getSelectedIndex()!=8){
for(int i=0;i<lines.length;i++){
if(Integer.valueOf(lines[i].substring(0,1)).intValue()!=sex.getSelectedIndex()||Integer.valueOf(lines[i].substring(1,2)).intValue()!=occupation.getSelectedIndex())lines[i]="00";
}}else if(occupation.getSelectedIndex()==8){
for(int i=0;i<lines.length;i++){
if(Integer.valueOf(lines[i].substring(0,1)).intValue()!=sex.getSelectedIndex()||(Integer.valueOf(lines[i].substring(1,2)).intValue()!=4&&Integer.valueOf(lines[i].substring(1,2)).intValue()!=5))lines[i]="00";
}}
}
int[] sexsum = new int[3];
int[] ocusum = new int[8];
int[] voted = new int[100];
int[] drawsum = new int[100];
int[] storysum =new int[100];
for(int i=0;i<lines.length;i++)lines[i]=lines[i].replace(" ","");
int lineslength = lines.length;
/* 数える */
for(int i=0;i<lines.length;i++) {
lines[i]=lines[i].replace(" ","");
if(lines[i].equals("00"))lineslength = lineslength-1;
sexsum[Integer.valueOf(lines[i].substring(0,1)).intValue()]++;
ocusum[Integer.valueOf(lines[i].substring(1,2)).intValue()]++;
System.out.println(lines[i]);
System.out.println(lines[i].substring(0,1));
System.out.println(lines[i].substring(1,2));
for(int k=0;4*k+2<lines[i].length();k++){
voted[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]++;
drawsum[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]+=Integer.valueOf(lines[i].substring(4*k+4,4*k+5)).intValue();
storysum[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]+=Integer.valueOf(lines[i].substring(4*k+5,4*k+6)).intValue();
System.out.println(lines[i].substring(4*k+2,4*k+4));
System.out.println(lines[i].substring(4*k+4,4*k+5));
System.out.println(lines[i].substring(4*k+5,4*k+6));
}
}
/* 総数表示 */
ranked.append("total :"+lineslength+"票 \n");
/* ソート条件選択 */
int[] sortby = new int[2];
sortby[0] = sex.getSelectedIndex();
sortby[1] = occupation.getSelectedIndex();
ranked.append("性別指定:"+sex.getSelectedItem()+", 職業指定:"+occupation.getSelectedItem()+"\n");
ranked.append(rankfor.getSelectedItem()+"\n\n");
/* ソート用変数宣言 */
int[] rankedindex = new int[101]; //作品番号を1位から順に格納
String[] rankedtitles = new String[101];
int[] rankedtimes = new int[101]; //得票数を1位から順に格納
int[] rankeddraws = new int[101]; //絵評価を1位から順に格納
int[] rankedstorys = new int[101]; //話評価を1位から順に格納
Double[] drawavg = new Double[101];
Double[] storyavg = new Double[101];
Double[] timespercent = new Double[101];
/* 0始まりか1始まりか */
if(one.isSelected()){
String[] shift = new String[101];
rankedtitles = titles.getText().split("\n");
for(int i=0;i<rankedtitles.length;i++)shift[i+1]=rankedtitles[i];
rankedtitles=shift;
rankedtitles[0]=null;
}else{
rankedtitles = titles.getText().split("\n");
}
for(int i=0;i<rankedtitles.length;i++){
rankedtimes[i] = voted[i];
rankeddraws[i] = drawsum[i];
rankedstorys[i] = storysum[i];
}
for(int i=0;i<rankedtitles.length;i++){
timespercent[i] = (double)voted[i]*100 / lineslength;
BigDecimal bit = new BigDecimal(timespercent[i]);
timespercent[i] = bit.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
if(voted[i]!=0){
drawavg[i] = (double)rankeddraws[i] / voted[i];
storyavg[i] = (double)rankedstorys[i] / voted[i];
BigDecimal bi = new BigDecimal(drawavg[i]);
BigDecimal bi2 = new BigDecimal(storyavg[i]);
drawavg[i] = bi.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
storyavg[i] = bi2.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
}else{
drawavg[i] = 0.0 ;
storyavg[i] = 0.0 ;
}
}
for(int i=0;i<rankedtitles.length;i++)System.out.println(rankedtitles[i]);
ranked.append(rankedtitles.length+"作品 \n");
/* 何順なのか */
if(rankfor.getSelectedIndex()==0){
/* 得票数順,votedでソート */
HashMap<Integer,Integer> tree = new HashMap<Integer,Integer>();
for (int i = 0; i < rankedtitles.length; i++) {
tree.put(i,voted[i]);
}
ArrayList<Map.Entry> array = new ArrayList<Map.Entry>(tree.entrySet());
Collections.sort(array,new Comparator<Object>(){
public int compare(Object o1, Object o2){
Map.Entry en1 =(Map.Entry)o1;
Map.Entry en2 =(Map.Entry)o2;
Integer en1Value = (Integer) en1.getValue();
Integer en2Value = (Integer) en2.getValue();
return (en2Value.compareTo(en1Value));
}
});
Iterator it = array.iterator();
ArrayList<Integer> indexes = new ArrayList<Integer>();
ArrayList<Integer> sortedValues = new ArrayList<Integer>();
while(it.hasNext()) {
Map.Entry obj = (Map.Entry)it.next();
indexes.add(Integer.valueOf(obj.getKey().toString()).intValue());
sortedValues.add(Integer.valueOf(obj.getValue().toString()).intValue());
}
int j=0;
boolean jj=false;
for(int i=0;i<rankedtitles.length;i++){
ranked.append(j+1+"位: "+rankedtitles[indexes.get(i)]+" "+sortedValues.get(i)+"票 ("+timespercent[indexes.get(i)]+"%)\n");
ranked.append("絵評価:"+drawavg[indexes.get(i)]+", 話評価:"+storyavg[indexes.get(i)]+"\n\n");
if(i<rankedtitles.length-1&&sortedValues.get(i)==sortedValues.get(i+1)){
if(jj==false){
j=i;
jj=true;}else if(jj==true){
}
}else{
j=i+1;
jj=false;}
}
ranked.append("------\n\n");
}else if(rankfor.getSelectedIndex()==1){
/* 絵評価順,drawavgでソート */
HashMap<Integer,Double> tree = new HashMap<Integer,Double>();
for (int i = 0; i < rankedtitles.length; i++) {
tree.put(i,drawavg[i]);
}
ArrayList<Map.Entry> array = new ArrayList<Map.Entry>(tree.entrySet());
Collections.sort(array,new Comparator<Object>(){
public int compare(Object o1, Object o2){
Map.Entry en1 =(Map.Entry)o1;
Map.Entry en2 =(Map.Entry)o2;
Double en1Value = (Double) en1.getValue();
Double en2Value = (Double) en2.getValue();
return (en2Value.compareTo(en1Value));
}
});
Iterator it = array.iterator();
ArrayList<Integer> indexes = new ArrayList<Integer>();
ArrayList<Double> sortedValues = new ArrayList<Double>();
while(it.hasNext()) {
Map.Entry obj = (Map.Entry)it.next();
indexes.add(Integer.valueOf(obj.getKey().toString()).intValue());
sortedValues.add(Double.valueOf(obj.getValue().toString()).doubleValue());
}
int j=0;
boolean jj=false;
for(int i=0;i<rankedtitles.length;i++){
ranked.append(j+1+"位: "+rankedtitles[indexes.get(i)]+" 絵評価:"+sortedValues.get(i)+"pt. \n");
if(i<rankedtitles.length-1&&Math.abs(sortedValues.get(i)-sortedValues.get(i+1))< 1.0e-6){
if(jj==false){
j=i;
jj=true;}else if(jj==true){
}
}else{
j=i+1;
jj=false;}
}
ranked.append("------\n\n");
}else if(rankfor.getSelectedIndex()==2){
/* 話評価順,storyavsでソート */
HashMap<Integer,Double> tree = new HashMap<Integer,Double>();
for (int i = 0; i < rankedtitles.length; i++) {
tree.put(i,storyavg[i]);
}
ArrayList<Map.Entry> array = new ArrayList<Map.Entry>(tree.entrySet());
Collections.sort(array,new Comparator<Object>(){
public int compare(Object o1, Object o2){
Map.Entry en1 =(Map.Entry)o1;
Map.Entry en2 =(Map.Entry)o2;
Double en1Value = (Double) en1.getValue();
Double en2Value = (Double) en2.getValue();
return (en2Value.compareTo(en1Value));
}
});
Iterator it = array.iterator();
ArrayList<Integer> indexes = new ArrayList<Integer>();
ArrayList<Double> sortedValues = new ArrayList<Double>();
while(it.hasNext()) {
Map.Entry obj = (Map.Entry)it.next();
indexes.add(Integer.valueOf(obj.getKey().toString()).intValue());
sortedValues.add(Double.valueOf(obj.getValue().toString()).doubleValue());
}
int j=0;
boolean jj=false;
for(int i=0;i<rankedtitles.length;i++){
ranked.append(j+1+"位: "+rankedtitles[indexes.get(i)]+" 絵評価:"+sortedValues.get(i)+"pt. \n");
if(i<rankedtitles.length-1&&Math.abs(sortedValues.get(i)-sortedValues.get(i+1))< 1.0e-6){
if(jj==false){
j=i;
jj=true;}else if(jj==true){
}
}else{
j=i+1;
jj=false;}
}
ranked.append("------\n\n");
}
}else if(e2.getSource() == tableput){
String lines[] = new String[2000];
lines = values.getText().split("\n");
for(int i=0;i<lines.length;i++)lines[i] = lines[i].substring(0,2);
int allvalues[][] = new int[9][4];
for(int i=0;i<lines.length;i++)allvalues[Integer.valueOf(lines[i].substring(1,2)).intValue()][Integer.valueOf(lines[i].substring(0,1)).intValue()]++;
for(int i=0;i<3;i++)for(int j=0;j<8;j++)allvalues[8][i]+=allvalues[j][i];
for(int i=0;i<9;i++)for(int j=0;j<3;j++)allvalues[i][3]+=allvalues[i][j];
tablevalue.append(",指定無,小学生,中学生,高校生,大学生,大学院,社会人,その他,合計\n");
tablevalue.append("指定無");
for(int i=0;i<9;i++)tablevalue.append(","+allvalues[i][0]);
tablevalue.append("\n");
tablevalue.append("男性");
for(int i=0;i<9;i++)tablevalue.append(","+allvalues[i][1]);
tablevalue.append("\n");
tablevalue.append("女性");
for(int i=0;i<9;i++)tablevalue.append(","+allvalues[i][2]);
tablevalue.append("\n");
tablevalue.append("合計");
for(int i=0;i<9;i++)tablevalue.append(","+allvalues[i][3]);
tablevalue.append("\n");
}else if(e2.getSource() == analyzeput){
String lines[] = new String[2000];
lines = values.getText().split("\n");
int numberget =0;
try{
numberget = Integer.valueOf(number.getText()).intValue();
if(numberget>lines.length)throw new NumberFormatException();
int[] sexsum = new int[3];
int[] ocusum = new int[8];
int[] voted = new int[100];
int[] drawsum = new int[100];
int[] storysum =new int[100];
for(int i=0;i<lines.length;i++)lines[i]=lines[i].replace(" ","");
boolean whatline[] = new boolean[2000];
int lineslength = lines.length;
for(int i=0;i<lines.length;i++) {
lines[i]=lines[i].replace(" ","");
if(lines[i].equals("00"))lineslength = lineslength-1;
sexsum[Integer.valueOf(lines[i].substring(0,1)).intValue()]++;
ocusum[Integer.valueOf(lines[i].substring(1,2)).intValue()]++;
for(int k=0;4*k+2<lines[i].length();k++){
voted[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]++;
if(voted[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]==numberget)whatline[i]=true;
drawsum[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]+=Integer.valueOf(lines[i].substring(4*k+4,4*k+5)).intValue();
storysum[Integer.valueOf(lines[i].substring(4*k+2,4*k+4)).intValue()]+=Integer.valueOf(lines[i].substring(4*k+5,4*k+6)).intValue();
}
}
String titlelist[] = new String[100];
titlelist = titles.getText().split("\n");
Double percent = (double)voted[numberget]*100 / lineslength;
BigDecimal pc = new BigDecimal(percent);
percent = pc.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
Double drawavg = (double)drawsum[numberget] / voted[numberget];
BigDecimal da = new BigDecimal(drawavg);
drawavg = da.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
Double storyavg = (double)storysum[numberget] / voted[numberget];
BigDecimal sa = new BigDecimal(storyavg);
storyavg = sa.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
analyzed.setText("");
analyzed.append(titlelist[numberget]+": "+voted[numberget]+"票 ("+percent+"%) \n");
analyzed.append("絵評価:"+drawavg+"pt. 話評価:"+storyavg+"pt.\n\n");
int allvalues[][] = new int[9][4];
for(int i=0;i<lines.length;i++){
if(whatline[i]==true){allvalues[Integer.valueOf(lines[i].substring(1,2)).intValue()][Integer.valueOf(lines[i].substring(0,1)).intValue()]++;
}}
for(int i=0;i<3;i++)for(int j=0;j<8;j++)allvalues[8][i]+=allvalues[j][i];
for(int i=0;i<9;i++)for(int j=0;j<3;j++)allvalues[i][3]+=allvalues[i][j];
analyzedtable.setText("");
analyzedtable.append(",指定無,小学生,中学生,高校生,大学生,大学院,社会人,その他,合計\n");
analyzedtable.append("指定無");
for(int i=0;i<9;i++)analyzedtable.append(","+allvalues[i][0]);
analyzedtable.append("\n");
analyzedtable.append("男性");
for(int i=0;i<9;i++)analyzedtable.append(","+allvalues[i][1]);
analyzedtable.append("\n");
analyzedtable.append("女性");
for(int i=0;i<9;i++)analyzedtable.append(","+allvalues[i][2]);
analyzedtable.append("\n");
analyzedtable.append("合計");
for(int i=0;i<9;i++)analyzedtable.append(","+allvalues[i][3]);
analyzedtable.append("\n");
}catch(NumberFormatException ex){
JOptionPane.showMessageDialog(null, "作品数以内の数字を入力してください。");
}}
}
/* 開くファイルの拡張子確認 */
class FileFilterForProgramAndData extends FileFilter {
public boolean accept(File f) {
if(f.isDirectory()) return true;
String s = f.getName();
int x = s.lastIndexOf('.');
if(x<0) return false;
String extention = s.substring(x+1).toLowerCase();
if(extention.equals("txt")) return true;
return false;
}
public String getDescription() { return "テキストファイル(*.txt)"; }
}
private static boolean checkBeforeReadfile(File file){
if (file.exists()){
if (file.isFile() && file.canRead()){
return true;
}
}
return false;
}
/* タブの動き */
public void stateChanged(ChangeEvent e) {
JTabbedPane t = (JTabbedPane)e.getSource();
if (t.getSelectedComponent() == settings) {
System.out.println("初期設定");
} else if (t.getSelectedComponent() == input){
System.out.println("入力");
}else{
System.out.println("集計");
}
}
/* main関数 */
public static void main(String args[]) {
new Tabs();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment