Polina Bee

Greenhorn
+ Follow
since Feb 17, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Polina Bee

Hi.
I'm not sure what do you want to do, but I changed your code so it now draws the pentagon and fills it with pattern of green hexagones.
You can play with sizes, shapes and colors.
Hope it helps.
Best regards.
Polina

/*
* MyPoly7A.java
*
* Created on April 21, 2004, 2:59 PM
*/
/**
*
* @author dbraxton
*/
// java packages are imported
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
// Graphics2D component
class MyPoly7A extends JPanel
{ public MyPoly7A()
{
setBackground( Color.red );
}
protected void paintComponent ( Graphics g )
{
super.paintComponent ( g );
Graphics2D g2d = ( Graphics2D ) g;
//g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
int width = getWidth ( );
int height = getHeight ( );
int cx = width / 2;
int cy = height / 2;
int dia = Math.min ( width, height ) / 4;
int strut = Math.min ( width, height ) * 3/4;
g2d.setPaint ( Color.blue );
g2d.draw ( new Rectangle2D.Double ( width / 16, height / 16, width * 7/8, height * 7/8 ) );
int R = ( int )( strut / (4 * Math.cos(Math.PI/5) * Math.sin( Math.PI / 5 ) ) );
int[ ] [ ] xy = generateShapeArrays( R, 5, cx, cy );

Polygon pentagon = new Polygon( xy [ 0 ], xy [ 1 ], 5);
g2d.setPaint( Color.white );
g2d.draw( pentagon );
// TROUBLE STARTS HERE LINE 47 follows
BufferedImage buffi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
Graphics2D buffig = buffi.createGraphics();
buffig.setColor(Color.white);
Rectangle textureRect= new Rectangle(0, 0, 15, 15);
buffig.fill(textureRect);
buffig.setColor(Color.green);
int[ ] [ ] xyp = generateShapeArrays(textureRect.height/2, 6, textureRect.x+textureRect.width/2, textureRect.y+textureRect.height/2);
Polygon smallHexagon = new Polygon( xyp [ 0 ], xyp[ 1 ], 6);
buffig.fill(smallHexagon);
Rectangle r = new Rectangle(0,0,25,25);
g2d.setPaint(new TexturePaint(buffi, r));
g2d.fill(pentagon);
}
private int [ ] [ ] generateShapeArrays(int R, int sides, int cx, int cy)
{
int[ ] x = new int[sides];
int[ ] y = new int[sides];
int radInc = 0;
if (sides % 2 == 0)
radInc = 1;
for(int counter = 0; counter < sides; counter++)
{
x [ counter ] = cx + ( int ) ( R * Math.sin ( radInc * Math.PI / sides ) );
y [ counter ] = cy - ( int ) ( R * Math.cos ( radInc * Math.PI / sides ) );
radInc += 2;
}
return new int[ ][ ]
{
x, y
};
}
}
20 years ago
Hi Douglas.
Just make setVisible(true) the last opeation in MyFrame constructor or remove it from constructor at all and put to the main function like this:
public static void main (String[ ] arg)
{
MyFrame mFrame = new MyFrame();
mFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mFrame.setVisible(true);
//System.exit(0);
}// terminate main
}// end of MyShapesDriver
Like it id now, your program tries to draw shapes before you create them and you're getting the NullPointerException.
Good luck.
Polina
20 years ago
Hi Anisa.
Does this Pharmaceutical company need more people.
I am looking for a job in this area, so cold you please give me a hint where to look.
Thanks a lot.
Polina
20 years ago
Hi.
This example is from sun.java Swing tutorial:
Detecting User Selections
The following code snippet shows how to detect when the user selects a table row. By default, a table allows the user to select multiple rows � not columns or individual cells � and the selected rows need not be next to each other. Using the setSelectionMode method, the following code specifies that only one row at a time can be selected.
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
...
//Ask to be notified of selection changes.
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm =
(ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
...//no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
...//selectedRow is selected
}
}
});
20 years ago
Hi Matthew.
I have just a guess. Looks like you create a new table every time. Did you try to remove the previous one from the content pane before adding a new one? You can also try to use the same table all the time and change just table date. Something like
row.removeAllElements();
while (blah bleh){
row.addElement(new data);
}
table.setTableData(row);
Good luck
Polina
20 years ago
This code works for me:
int j=1;
String[][] data = new String[j][2];
for (int k=0; k<j; k++){
String[] row = {"",""};
data[k] = row;
String[] columnNames = {"Table Name","Column Name"};
ivjScrollPaneTable = new javax.swing.JTable(data, columnNames);
ivjScrollPaneTable.getTableHeader().setForeground(java.awt.Color.magenta);
ivjScrollPaneTable.setName("ScrollPaneTable");
ivjScrollPaneTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
ivjScrollPaneTable.setSelectionForeground(java.awt.Color.black);
ivjScrollPaneTable.setForeground(java.awt.Color.black);
ivjScrollPaneTable.setGridColor(java.awt.Color.black);
ivjScrollPaneTable.setBounds(0, 0, 450, 400);
ivjScrollPaneTable.setSelectionBackground(java.awt.Color.white);
JScrollPane scrollPane = new JScrollPane(ivjScrollPaneTable);
ivjScrollPaneTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
20 years ago