Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Screen extends Frame {
private static final int SIZE = 1000;
private static final double xMin = -600;
private static final double xMax = 600;
private static final double yMin = -4;
private static final double yMax = 4;
private static final double xMinDetail = -5;
private static final double xMaxDetail = 5;
public Screen() {
this.setSize(SIZE,SIZE);
addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { dispose();}});
}
public void paint(Graphics g) {
zeicheKoordinatenSystem(g);
for(double x = xMin; x < xMax; x += 0.01 ){
g.setColor(Color.BLACK);
g.drawLine(berechneXPixel(x), berechneYPixel(f(x)), berechneXPixel(x), berechneYPixel(f(x)));
g.setColor(Color.RED);
g.drawLine(berechneDetailXPixel(x), berechneYPixel(f(x)), berechneDetailXPixel(x), berechneYPixel(f(x)));
}
}
private void zeicheKoordinatenSystem(Graphics g) {
zeichneXAchse(g);
zeichneYAchse(g);
}
private void zeichneXAchse(Graphics g) {
int startx = berechneXPixel(xMin);
int endx = berechneXPixel(xMax);
int starty = berechneYPixel(0);
int endy = berechneYPixel(0);
g.drawLine(startx, starty, endx, endy);
}
private void zeichneYAchse(Graphics g) {
int startx = berechneXPixel(0);
int endx = berechneXPixel(0);
int starty = berechneYPixel(yMin);
int endy = berechneYPixel(yMax);
g.drawLine(startx, starty, endx, endy);
}
private int berechneXPixel(double x) {
double pixelBreite = ((xMax - xMin) / (double)getWidth());
return (int) ((x - xMin) / pixelBreite );
}
private int berechneDetailXPixel(double x) {
double pixelBreite = ((xMaxDetail - xMinDetail) / (double)getWidth());
return (int) ((x - xMinDetail) / pixelBreite );
}
private int berechneYPixel(double y) {
double pixelBreite = ((yMax - yMin) / (double)getHeight());
return getHeight() - ((int) ((y - yMin) / pixelBreite));
}
private double f(double x) {
return Math.sin(x /2);
}
public static void main(String[] args) {
new Screen().setVisible(true);
}
}
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Screen extends Frame {
private static final int SIZE = 1000;
private static final double xMin = -600;
private static final double xMax = 600;
private static final double yMin = -7.7;
private static final double yMax = 4.3;
private static final double xMinDetail = -5;
private static final double xMaxDetail = 5;
private static final double yMinDetail = -3.2;
private static final double yMaxDetail = 1.3;
public Screen() {
this.setSize(SIZE,SIZE);
addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { dispose();}});
}
public void paint(Graphics g) {
zeicheKoordinatenSystem(g);
for(double x = xMin; x < xMax; x += 0.01 ){
g.setColor(Color.BLACK);
g.drawLine(berechneXPixel(x), berechneYPixel(f(x)), berechneXPixel(x), berechneYPixel(f(x)));
g.setColor(Color.RED);
g.drawLine(berechneDetailXPixel(x), berechneDetailYPixel(f(x)), berechneDetailXPixel(x), berechneDetailYPixel(f(x)));
}
}
private void zeicheKoordinatenSystem(Graphics g) {
zeichneXAchse(g);
zeichneYAchse(g);
zeichneXDetailAchse(g);
}
private void zeichneXAchse(Graphics g) {
int startx = berechneXPixel(xMin);
int endx = berechneXPixel(xMax);
int starty = berechneYPixel(0);
int endy = berechneYPixel(0);
g.drawLine(startx, starty, endx, endy);
}
private void zeichneYAchse(Graphics g) {
int startx = berechneXPixel(0);
int endx = berechneXPixel(0);
int starty = berechneYPixel(yMin);
int endy = berechneYPixel(yMax);
g.drawLine(startx, starty, endx, endy);
}
private void zeichneXDetailAchse(Graphics g) {
int startx = berechneDetailXPixel(xMin);
int endx = berechneDetailXPixel(xMax);
int starty = berechneDetailYPixel(0);
int endy = berechneDetailYPixel(0);
g.setColor(Color.RED);
g.drawLine(startx, starty, endx, endy);
}
private int berechneXPixel(double x) {
double pixelBreite = ((xMax - xMin) / (double)getWidth());
return (int) ((x - xMin) / pixelBreite );
}
private int berechneDetailXPixel(double x) {
double pixelBreite = ((xMaxDetail - xMinDetail) / (double)getWidth());
return (int) ((x - xMinDetail) / pixelBreite );
}
private int berechneYPixel(double y) {
double pixelBreite = ((yMax - yMin) / (double)getHeight());
return getHeight() - ((int) ((y - yMin) / pixelBreite));
}
private int berechneDetailYPixel(double y) {
double pixelBreite = ((yMaxDetail - yMinDetail) / (double)getHeight());
return getHeight() - ((int) ((y - yMinDetail) / pixelBreite));
}
private double f(double x) {
return Math.sin(x /2);
}
public static void main(String[] args) {
new Screen().setVisible(true);
}
}
private void zeichneXAchse(Graphics g) {
g.setColor(Color.GREEN);
g.drawLine(berechneXPixel(xMin),berechneYPixel(0) , berechneXPixel(xMax), berechneYPixel(0));
for(double i = xMin; i < xMax; i += (xMax - xMin) / 20)
{
g.drawLine(berechneXPixel(i),berechneYPixel(0.5) , berechneXPixel(i), berechneYPixel(-0.5));
g.drawString("" + i, berechneXPixel(i), berechneYPixel(-1));
}
}
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.geom.Ellipse2D;
public class TTest extends JFrame{
/**
*
*/
public TTest() {
super();
setBackground(Color.gray);
setLayout(new BorderLayout());
setVisible(true);
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setResizable(false);
// TODO Auto-generated constructor stub
Canvas panel = new PaintPanel(12.3,10);
add(panel);
show();
}
public static void main(String[] args){
new TTest();
}
}
class PaintPanel extends Canvas{
final static int PAINTX = 500; //Pixel in x- ...
final static int PAINTY = 500;
final AffineTransform FLIP_X_COORDINATE;
double stand;
double ge;
public PaintPanel(double stand, double ge){
this.stand = stand;
this.ge = ge;
FLIP_X_COORDINATE = AffineTransform.getTranslateInstance(PAINTX/2 ,PAINTY/2);
setPreferredSize(new Dimension(PAINTX,PAINTY));
// Größe der Paintfläche
setBackground(Color.WHITE);
//Hintergrund der Paintfläche
}
/**
* @param füllstand
* @param waage
*/
private void zeichneToken(Graphics2D g) {
// TODO Auto-generated method stub
double a = 12.2 - stand;
g.fill(new Ellipse2D.Double(ge*8-5,a*800-5,10,10));
//g.draw( new Line2D.Double(ge*8, -15, ge*8, 15));
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.setTransform(FLIP_X_COORDINATE);
g2.drawLine(-4800,0,4800,0);
g2.drawLine(0,-3000,0,3000);
g2.drawLine(0,0,4800,-4800);
g2.drawLine(0,0,4800,-9000);
g2.draw(new Line2D.Double(0, 0, 4800, -15360));
Color col = new Color(102,184,0);
g2.setColor(col);
g2.fillRect(-40,-40,80,80);
g2.setColor(Color.BLACK);
g2.drawLine(40,-4,40,4);
//g2.drawString("5",40-6,+16);
//erste Bereich von unten (rechts)
int x2Points[] = {40, 40, 4800, 4800};
int y2Points[] = {-40, 0,0,-4800};
GeneralPath polyline =
new GeneralPath(GeneralPath.WIND_EVEN_ODD, x2Points.length);
polyline.moveTo (x2Points[0], y2Points[0]);
for (int index = 1; index < x2Points.length; index++) {
polyline.lineTo(x2Points[index], y2Points[index]);
};
//GradientPaint redtowhite4 = new GradientPaint(0,20,Color.GREEN,100, 100,Color.WHITE);
Color col2 = new Color(255,230,204);
g2.setColor(col2);
g2.fill(polyline);
// dritte Bereich von unten (rechts)
double x3Points[] = {12.5, 4800, 0, 0};
double y3Points[] = {-40, -15360,-15360,-40};
GeneralPath polyline3 =
new GeneralPath(GeneralPath.WIND_EVEN_ODD, x3Points.length);
polyline3.moveTo (x3Points[0], y3Points[0]);
for (int index = 1; index < x3Points.length; index++) {
polyline3.lineTo(x3Points[index], y3Points[index]);
};
//GradientPaint redtowhite4 = new GradientPaint(0,20,Color.GREEN,100, 100,Color.WHITE);
Color col3 = new Color(255,204,204);
g2.setColor(col3);
g2.fill(polyline3);
//zweite Bereich von unten (rechts)
double x4Points[] = {40, 4800, 4800, 12.5};
double y4Points[] = {-40, -4800,-15360,-40};
GeneralPath polyline4 =
new GeneralPath(GeneralPath.WIND_EVEN_ODD, x4Points.length);
polyline4.moveTo (x4Points[0], y4Points[0]);
for (int index = 1; index < x4Points.length; index++) {
polyline4.lineTo(x4Points[index], y4Points[index]);
};
//GradientPaint redtowhite4 = new GradientPaint(0,20,Color.GREEN,100, 100,Color.WHITE);
Color col4 = new Color(213,211,252);
g2.setColor(col4);
g2.fill(polyline4);
g2.setColor(Color.BLACK);
//dritte Bereich von unten (rechts)
double x5Points[] = {0,0,-4800,-4800,-40, -40};
double y5Points[] = {-40, -15360,-15360,0,0,-40};
GeneralPath polyline5 =
new GeneralPath(GeneralPath.WIND_EVEN_ODD, x5Points.length);
polyline5.moveTo (x5Points[0], y5Points[0]);
for (int index = 1; index < x5Points.length; index++) {
polyline5.lineTo(x5Points[index], y5Points[index]);
};
//GradientPaint redtowhite4 = new GradientPaint(0,20,Color.GREEN,100, 100,Color.WHITE);
Color col5 = new Color(255,153,153);
g2.setColor(col5);
g2.fill(polyline5);
g2.setColor(Color.BLACK);
//g2.drawLine(-40,-4,-40,4);
//g2.drawString("-5",-40-8,+16);
for(int i=1; i<= 9; i++){
int x = 10*i;
String xx = (new Integer(x)).toString();
g2.drawLine(8*x,-4,8*x,4);
g2.drawString(xx,8*x -8,+16);
}
for(int i=0; i<=10; i++){
int x = 100 + 50*i;
String xx = (new Integer(x)).toString();
g2.drawLine(8*x,-4,8*x,4);
g2.drawString(xx,8*x -8,+16);
}
for(int i=1; i<= 9; i++){
int x = -10*i;
String xx = (new Integer(x)).toString();
g2.drawLine(8*x,-4,8*x,4);
g2.drawString(xx,8*x -8,+16);
}
for(int i=0; i<=10; i++){
int x = -(100 + 50*i);
String xx = (new Integer(x)).toString();
g2.drawLine(8*x,-4,8*x,4);
g2.drawString(xx,8*x -8,+16);
}
int c = 12 ;
for(int i = 2; i <= 7 ; i++){
double xc = (i+2)*0.1;
int xxx = -80*i ;
String xx = (new Double(xc)).toString();
g2.drawLine(-4,xxx,+4,xxx);
g2.drawString(xx,-32,xxx);
}
for(int j = 1; j <= 3; j++){
//int j = 12;
for(int i = 0; i <= 9 ; i++){
double xc = (c + j + 0.10*i );
int xxx = -80*i - 800*(j-1) -640;
String xx = (new Double(xc)).toString();
g2.drawLine(-4,xxx,+4,xxx);
g2.drawString(xx,-32,xxx);
}
zeichneToken(g2);
}
}
}
Dies scheint mit aber kein Javaproblem und schon gar kein Grundlagenproblem zu sein. Dein Problem ist, wenn ich es richtig verstanden habe, dass Du EIN Koordinatensystem mit verschiedenen Skalen brauchst.
Auf der X-Achse könnte die Abstände etwa so aussehen (grob skizziert)
||||| | | | | |||||
analog dazu die Y-Achse
wobei die großen Abstände den 5-Bereich, die kleinen den 600 darstellen. Habe ich das soweit jetzt verstanden?