毎度、お世話になります。 『JTextFiledの割込み処理について』、本日、ありがたいお教えを頂きまして 有難う御座います。 私のAppに合わせまして、変更、改良を行いました(下記のコードを参照ください)。 第2行目と第3行目を同じマウスの割込みルーチンで行います方式のコードを作成しましたが、 その結果は下記の通りです。 ===================== 第2行目のUp0,Up1....Up20に関しましては、バックグランドの色の変更はお陰で出来ました。 第3行目のLw0,Lw1....Lw20に関しましては、実行時にエラーがおきて、色の変更は 出来ませんでした。(添付のTextField.jpegを参照ください) Appのコード=================== package pkg; import static java.lang.Math.*; public class EventSample2 { static public double a=PI; // コンポーネントを作成 static JTextField[] titlen = new JTextField[21]; static JTextField[] dataUpLw = new JTextField[42]; //下記の行を纏める //static JTextField[] dataLw = new JTextField[21]; static JTextField[] dataMsr = new JTextField[21]; //static String[] sdata=new String[2]; static String[] s_title={"t0","t1","t2","t3","t4","t5","t6","t7","t8","t9","t10","t11", "t12","t13","t14","t15","t16","t17","t18","t19","20"}; static String[] s_dataUpLw={"Up0","Up1","Up2","Up3","Up4","Up5","Up6","Up7","Up8","Up9","Up10","Up11", "Up12","Up13","Up14","Up15","Up16","Up17","Up18","Up19","Up20", "Lw0","Lw1","Lw2","Lw3","Lw4","Lw5","Lw6","Lw7","Lw8","Lw9","Lw10","Lw11", "Lw12","Lw13","Lw14","Lw15","Lw16","Lw17","Lw18","Lw19","Lw20"}; static String[] s_dataMsr={"Msr0","Msr1","Msr2","Msr3","Msr4","Msr5","Msr6","Msr7","Msr8","Msr9","Msr10","Msr11", "Msr12","Msr13","Msr14","Msr15","Msr16","Msr17","Msr18","Msr19","Msr20"}; static int HColor[]=new int[21]; //+する事 public static void main(String[] args) { JFrame frame = new JFrame("イベントのサンプル"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); a=Math.PI; for (int i=0; i<21; i++){ HColor[i]=0; } // コンポーネントを作成 for(int i=0; i<21; i++){ titlen[i] = new JTextField(s_title[i]); } for(int i=0; i<42; i++){ dataUpLw[i] = new JTextField(s_dataUpLw[i]); } for(int i=0; i<21; i++){ dataMsr[i] = new JTextField(s_dataMsr[i]); } for(int i=0; i<21; i++){ titlen[i].setBackground(java.awt.Color.LIGHT_GRAY); //staticでok } // 一つにまとめられることは一つにしましょう<---感謝 class DataUpMouseListener extends java.awt.event.MouseAdapter { private int fieldIndex; public DataUpMouseListener(int fieldIndex) { this.fieldIndex = fieldIndex; } public void mouseClicked (java.awt.event.MouseEvent evt) { if(evt.getClickCount () == 1) { //System.out.println("Click"); } else if(evt.getClickCount () == 2) { mouseDoubleClicked (evt); //System.out.println("Double Click"); } } void mouseDoubleClicked (java.awt.event.MouseEvent evt) { switch(HColor[fieldIndex]){ case 0: HColor[fieldIndex]=1; dataUpLw[fieldIndex].setBackground(java.awt.Color.GREEN); break; case 1: HColor[fieldIndex]=0; dataUpLw[fieldIndex].setBackground(java.awt.Color.WHITE); break; default: break; } dataUpLw[fieldIndex].setText(dataUpLw[fieldIndex].getText() ); } } // dataUpLw.length=42となっている System.out.println("dataUpLw.length="+dataUpLw.length); for (int i = 0; i
↧