private static final int row = 9; private static final int col = 9;
int[][] fields = new int[row][col]; JTextField[][] texts = new JTextField[row][col];
Dimension fieldsize = new Dimension(25, 25);
Dimension tSize = new Dimension(279, 279);
JPanel panel2;
ImageIcon icon; Image waku;
public NText(){ setPreferredSize(tSize);
for(int i = 0; i < row; i++){ int y = i; for(int j = 0; j < col; j++){ int x = j;
texts[y][x] = new JTextField(); texts[y][x].setPreferredSize(fieldsize); this.add(texts[y][x]); } } }
public void paint(Graphics g){
icon = new ImageIcon(getClass().getResource("waku.gif")); waku = icon.getImage();
g.drawImage(waku, 0, 0, null); } }
5件の回答
評価
0
ひどい我流のコードを書いていると、進歩がひどく遅れますよ。 ご参考までに: ----------------------------------- /* save and compile as NnText.java */ import javax.swing.*; import java.awt.*;
public class NnText extends JPanel{ private static final int row = 9; private static final int col = 9;
public NnText(){ fields = new int[row][col]; texts = new JTextField[row][col]; fieldsize = new Dimension(25, 25); tSize = new Dimension(279, 279); icon = new ImageIcon(getClass().getResource("waku.gif")); waku = icon.getImage(); setPreferredSize(tSize);
for(int i = 0; i < row; i++){ int y = i; for(int j = 0; j < col; j++){ int x = j; texts[y][x] = new JTextField(); texts[y][x].setPreferredSize(fieldsize); this.add(texts[y][x]); } } }
public void paintComponent(Graphics g){ super.paintComponent(g); g.drawImage(waku, 0, 0, null); }
public static void main(String[] args){ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new NnText());