Graphics2D g2 = (Graphics2D) MeinProgView.JPanel2.getGraphics();
/*
* In_Pan3View.java
*/
package in_pan3;
import java.awt.Color;
import java.awt.Graphics;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* The application's main frame.
*/
public class In_Pan3View extends FrameView {
static public Graphics grafik1;
public int MyInit=0;
Color C;
public int x;
public static int mx=100,my=100;
static JPanel JP2 = new JPanel();
MyDraw md = new MyDraw();
public In_Pan3View(SingleFrameApplication app) {
super(app);
initComponents();
initMyComponents(); // Steht ganz unten zum Panel initialisieren.
{...}
}
{...}
private void JB_ZeichneMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JB_ZeichneMousePressed
// TODO add your handling code here:
if ( MyInit == 0 )
{
MyInit = 1;
grafik1 = JP2.getGraphics(); // Ist eigentlich nicht notwendig
}
JP2.repaint();
}//GEN-LAST:event_JB_ZeichneMousePressed
private void mainPanelMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mainPanelMouseMoved
// TODO add your handling code here:
if ( MyInit == 0 )
{
MyInit = 1;
grafik1 = JP2.getGraphics(); // Ist eigentlich nicht notwendig
}
mx=evt.getX();
my=evt.getY();
JP2.paintComponents(grafik1);
}//GEN-LAST:event_mainPanelMouseMoved
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton JB_Zeichne;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration//GEN-END:variables
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
private void initMyComponents()
{
JP2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
JP2.setLocation(150,25);
JP2.setSize(md.xmax,md.ymax);
mainPanel.add(JP2);
JP2.add(md);
JP2.setVisible( true );
}
}
package in_pan3;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
public class MyDraw extends JPanel
{
public int xmax=100,ymax=100;
public MyDraw()
{ }
@Override
public void paintComponent(Graphics g1)
{
super.paintComponent(g1);
//super.paintComponent(In_Pan3View.grafik1);
//Graphics2D g2 = (Graphics2D) In_Pan3View.grafik1;
//Graphics2D g2 = (Graphics2D) g1;
int i=0;
Color C;
g1.setColor(Color.BLACK);
for ( i=0 ;i<=xmax;i++)
{
g1.drawLine(0,i,xmax,i);
}
g1.setColor(Color.YELLOW);
g1.drawLine(0,0,xmax,ymax);
g1.setColor(Color.RED);
g1.drawLine(0,0,In_Pan3View.mx,In_Pan3View.my);
}
}