/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Bug221242;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author ADu
*/
public class Bug221242Test {
private JPanel bugPane;
class BugPanel extends JPanel {
private int bugWidth = 600;
private int bugHeight = 400;
private double bugXmin = -240d;
private double bugXmax = +240d;
private double bugYmin = -160d;
private double bugYmax = +160d;
private java.awt.FontMetrics bugFM;
BugPanel() {
super();
setBackground(Color.BLACK);
setPreferredSize(new Dimension(bugWidth,bugHeight));
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics bugGraphics = g.create();
bugGraphics.setColor(Color.WHITE);
double scaleX = bugWidth/(bugXmax-bugXmin);
double scaleY = bugHeight/(bugYmax-bugYmin);
float floatScale = (new Double(scaleX)).floatValue();
this.bugFM = g.getFontMetrics();
double eps = -1.e-14;
double xx, yy, zz;
xx = 0;
xx = 0.5;
zz = eps;
yy = Math.sqrt(1-xx*xx-zz*zz)-eps;
double phi = Math.asin(zz);
double argum = yy/Math.cos(phi);
double theta = Math.asin(argum); // If xx==0.0d, then theta is
NaN !
String nivString;
Graphics2D g2D = (Graphics2D)g.create(); // le
<code>Graphics<code> pour dessiner les échelons d'attitude
g2D.setColor(Color.WHITE);
g2D.scale(scaleX,scaleY);
g2D.translate(-bugXmin, -bugYmin);
g2D.rotate(theta);
for (int j = 0; j<10 ; j++) {
int niveau = 10*j;
double decal = 20*j;
nivString = '+'+Integer.toString(niveau);
g2D.translate(0,-floatScale*decal);
g2D.drawLine(-100, 0, 100, 0);
g2D.drawString(nivString,
-100-5-this.bugFM.stringWidth(nivString), 0);
g2D.drawString(nivString, 100+5, 0);
g2D.translate(0,2*floatScale*decal);
g2D.drawLine(-100, 0, 100, 0);
nivString = '-'+Integer.toString(niveau);
g2D.drawString(nivString,
-100-5-this.bugFM.stringWidth(nivString), 0);
g2D.drawString(nivString, 100+5, 0);
g2D.translate(0,-floatScale*decal);
}
}
}
/**
* Creates a panel where crosses will be drawn
*/
public Bug221242Test() {
this.bugPane = new BugPanel();
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Bug 221242 test");
frame.setLocation(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
Bug221242Test bugTest = new Bug221242Test();
bugTest.bugPane.setOpaque(true); //content panes is opaque
frame.setContentPane(bugTest.bugPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
1 / 3 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !