Question: This is in Java language . Draw the following graph. The graph must stay in the middle, regardless the size of the window borders. If

This is in Java language . Draw the following graph. The graph must stay in the middle, regardless the size of the window borders. If the window is resized, the graph should be around 75 pixels away from the window borders. (Use:Graphics class)

import java.awt.Graphics;

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * * @author DELL */ public class MyFrame extends javax.swing.JFrame {

/** * Creates new form MyFrame */ public MyFrame() { initComponents(); }// THIS IS MAIN METHOD (DO LIKE THIS ) public void paint (Graphics g){ super.paint(g); g.translate(this.getWidth()/2, this.getHeight()/2); double x_gap = (this.getWidth()/2 - 75)/10.0; double y_gap = (this.getHeight()/2 -75)/10.0; for (int i = 0; i private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) );

pack(); }//

/** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MyFrame().setVisible(true); } }); }

// Variables declaration - do not modify // End of variables declaration }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!