1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class Interface_1 extends JFrame {
private static final long serialVersionUID = 1L;
private JTextField text;
private Image bufferedImage;
Interface_1(String name) {
super(name);
setSize(new Dimension(400, 200));
JPanel panel = new JPanel();
FlowLayout flayout = new FlowLayout(FlowLayout.LEFT);
panel.setLayout(flayout);
JLabel label = new JLabel("x =");
this.text = new JTextField();
this.text.setPreferredSize(new Dimension(30, 20));
this.text.setBackground(getForeground());
panel.add(label);
panel.add(this.text);
setContentPane(panel);
setVisible(true);
// opération par défaut à la fermeture
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@SuppressWarnings("null")
public void paint(Graphics g, final int resultat) {
this.bufferedImage = new BufferedImage(10, 10,
BufferedImage.TYPE_4BYTE_ABGR);
((BufferedImage) this.bufferedImage).createGraphics();
Graphics graph = null;
graph.setColor(Color.black);
graph.fillRect(0, 0, 10, 10);
g.drawImage(this.bufferedImage, resultat, 30, 10, 10, this);
}
public void setResultat1(final int resultat) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
text.setText("" + resultat);
}
});
}
} |
Partager