** Button
Label
TextField
のようなコンポーネントの位置を変更しようとすると、私の形状の一部が見えなくなります。 TextField
)の形が正常になります。 **コンポーネントの位置を変更した後に形状が見えなくなる
public class Line {
public static void main(String[] args) {
JFrame frame = new JFrame("JFrame Example");
frame.setSize(1366, 768);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.setVisible(true);
JButton button=new JButton("Show lines");
frame.add(button);
button.setBounds(60, 400, 220, 30);
button.setVisible(true);
JTextField txtf=new JTextField();
frame.add(txtf);
txtf.setVisible(true);
txtf.setSize(50, 100);
button.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent me) {
button.setVisible(false);
Graphics2D grf= (Graphics2D) frame.getGraphics();
txtf.setVisible(false);
txtf.setText("APPLE");
txtf.setLocation(600, 600);
txtf.setVisible(true);
grf.fillOval(600, 600, 10, 10);
grf.fillOval(190, 600, 10, 10);
grf.fillOval(900, 650, 10, 10);
grf.fillOval(750, 160, 10, 10);
grf.fillOval(600, 400, 10, 10);
grf.fillOval(1139, 266, 10, 10);
grf.drawLine(1144, 271, 605, 405);
grf.drawLine(195, 605, 605, 405);
grf.drawLine(755, 165, 605, 405);
grf.drawLine(755, 165, 1144, 271);
grf.drawLine(905, 655, 1144, 271);
grf.drawLine(905, 655, 605, 405);
grf.drawLine(205, 205, 605, 405);
grf.drawLine(205, 205, 755, 165);
}
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
});
button.setVisible(true);
}
}
1)Java GUIは、異なるロケールで異なるPLAFを使用する異なるOS、画面サイズ、画面解像度などで動作する必要があります。したがって、ピクセルの完全なレイアウトには役立ちません。代わりに、レイアウトマネージャや[それらの組み合わせ](http://stackoverflow.com/a/5630271/418556)と[空白](http://stackoverflow.com/a/17874718/)のレイアウトパディングとボーダーを使用してください。 418556)。 2)コードとコードスニペット、HTML/XMLや入出力のような構造化文書にはコードの書式を使用してください。これを行うには、テキストを選択し、メッセージの投稿/編集フォームの上部にある「{}」ボタンをクリックします。 –
3)すぐに役立つようにするには、[MCVE]または[短く、自己完結型の正しい例](http://www.sscce.org/)を投稿してください。 –