|
|
Hi to all, I need some help in getting the union of of 2 interacting polygons.
Currently I have managed to draw 2 polygons p1 and p2, and I got stuck on getting the unions between the 2 polygons. I have tried using the java.awt.geom, but later realized that the geom package can only be used for regular shapes.
This is part of my code:
Polygon p1 = new Polygon();
for (int i = 0; i < 5; i++)
p1.addPoint((int) (200 + 50 * Math.cos(i * 2 * Math.PI / 5)),
(int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));
g.drawPolygon(p1);
Polygon p2 = new Polygon();
for (int i = 0; i < 5; i++)
p2.addPoint((int) (160 + 50 * Math.cos(i * 2 * Math.PI / 6)),
(int) (60 + 50 * Math.sin(i * 2 * Math.PI / 6)));
g.drawPolygon(p2);
Please help. Thanks.
|
|
|
|
|
|
1) we don't do homework here.
2) read the forums posting guidelines
3) "the int type has a limitation: it can’t store integer values larger
than 231"
Where the f*ck does this come from ?????
|
|
|
|
|
I would assume that by 231 he means 2^31, which is the limitation for a signed int.;
As for the question, what you are going to have to do is remember back to gradeschool, when we did longhand arithmetic.
1001
2009
----
3010
Write out psuedo code on how to do this, then implement it. isValidBigInt should be easy.
|
|
|
|
|
TannerB wrote: I would assume that by 231 he means 2^31
this is fundamentaly different, and moreover, WRONG.
the higher value an unsigned int can take is (2^32)-1, which is 4 294 967 295.
|
|
|
|
|
Thanks, must of had a brain fart when I read it.
|
|
|
|
|
As far as I remember, there is only signed int in Java, so its maximum value would be (2^31)-1 (2,147,483,647).
My LinkedIn Profile
|
|
|
|
|
I've got this here code I just started today for an assigment, it is all working (so I'm not asking you to do it for me :P). What this code does is it considers any @ to be a backspace and deletes the character before it. I was supposed to use indexOf() and substring() but I thought using regular expressions would be simpler, and a learning experience at the same time. I think my problem right now is that I have stared at it for too long. What I want is for the loop in main to be ran atleast once but it seems weird to have the while(checkForError(input)); ran and then have it ran again in the method fixErrors . Any thoughts on what I could do to fix this would be welcome. Other comments and critiques are always welcome.
Thanks,
Tanner
EDIT: Update at bottom.
import javax.swing.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class bruce_tanner_A3Q3
{
public static void main(String [] args)
{
String input;
do
{
input = getString("Enter a string");
printOutput(fixErrors(input));
}while(checkForError(input));
}
public static boolean checkForError(String input)
{
Pattern pattern = Pattern.compile("@");
Matcher matcher = pattern.matcher(input);
return matcher.find();
}
public static String getString(String input)
{
String tempString = JOptionPane.showInputDialog(input);
return tempString;
}
public static void printOutput(String tempString)
{
System.out.println(tempString);
}
public static String fixErrors(String tempString)
{
if(checkForError(tempString))
{
Pattern pattern = Pattern.compile("[^@][@?+]");
Matcher matcher = pattern.matcher(tempString);
while(matcher.find())
{
tempString = matcher.replaceAll("");
matcher = pattern.matcher(tempString);
}
pattern = Pattern.compile("@");
matcher = pattern.matcher(tempString);
tempString = matcher.replaceAll("");
return tempString;
}
return "This string is error free";
}
}
I'm not sure whether this was a flash of brilliance or not but it works.
New main code:
public static void main(String [] args)
{
String input;
for(input = getString("Enter a string"); checkForError(input); input = getString("Enter a string"))
{
printOutput(fixErrors(input));
}
printOutput("This string is error free");
}
New fixErrors:
public static String fixErrors(String tempString)
{
Pattern pattern = Pattern.compile("[^@][@?+]");
Matcher matcher = pattern.matcher(tempString);
while(matcher.find())
{
tempString = matcher.replaceAll("");
matcher = pattern.matcher(tempString);
}
pattern = Pattern.compile("@");
matcher = pattern.matcher(tempString);
tempString = matcher.replaceAll("");
return tempString;
}
modified on Monday, November 3, 2008 2:57 PM
|
|
|
|
|
I have a Swing based application which consists of 5 classes.
Now I want to make the whole application as an exe file.
Can some one help me in this regard......
|
|
|
|
|
do you use an IDE ? if yes, which ?
|
|
|
|
|
you can download the jet engine exe file then u can attach the class files and then run which is very very useful jet is available at sun products
Ambedkar Golla
|
|
|
|
|
Use this tool:
JSmooth
The downlodad URL is:
http://www.ej-technologies.com/download/exe4j/files.php
If you don't know the package method send a mail to me. [soief@qq.com]
|
|
|
|
|
how to develop installation web application software using java(servlets,jsp),java script,mysql(database).
|
|
|
|
|
I have this problem,
I need to represent set in the following form
[L,R]
where L is the left hand-bound of the set , and R is the right hand-bound
each of L and R are a collection of sets
for example
L= [{1},{2},{2,3}]
R=[{1,2,3},{2,3,4}]
[L,R]= [{ {1},{2},{2,3} } , { {1,2,3},{2,3,4} }]
how can i do this in java
|
|
|
|
|
There are many ways that you could represent this depending on what you are trying to do. My initial thought is a 2 element array of sets of sets e.g.
Set s1 = new Set();
s1.add(1)
Set s2 = new Set();
s2.add(2)
Set s23 = new Set();
s23.add(3)
s23.add(2)
Set left = new Set{}
left.add(s1}
left.add(s2}
left.add(s23}
/*
* Prepare Right Side now
*/
Set[] allSets = new Set[2]()
allSets[0] = left;
allSets[1] = right;
Do the Sets in L and R have to be unique. Also why are you modelling the sets what do you expect to do with them. If it is a bit more rigid and you want to perform operations on the sets you may want to use a class to model them
e.g.
public Class LeftRightSet() {
private Set<set><string> left;
private Set<set><string>> right;
// Further manipulation classes
}
Hope this helps
|
|
|
|
|
Hi all,
I need to find the coordinates of the selected item in my JList. I'd expect this line of code to be defined in swing, but it's not.
selectedItemY = [JList Name].getSelectedValue().getY();
Any suggestion?
Thanks
Naz
|
|
|
|
|
How can I compile my java code without going to a DOS window?
Everything makes sense in someone's mind
|
|
|
|
|
I use NetBeans IDE where every function is visually available. So you never need to use the cmd. You can download it for free.
|
|
|
|
|
KMAROIS wrote: How can I compile my java code without going to a DOS window?
by using an IDE...
the best I ever used is definitely Eclipse:
Eclipse for J2SE[^]
Eclipse for J2EE[^]
|
|
|
|
|
The RAD is better.
but not free.
|
|
|
|
|
Hi,
I've followed this article (http://java.sun.com/developer/technicalArticles/J2EE/AJAX/[^]) to create a Java Servlet and retrieve data from it using AJAX. In this example the doGet method is automatically run and it gives me the required output, however I would like to have additional methods in this class returning different things that I can call on demand, how would I do this?
Thanks in advance
|
|
|
|
|
Hi, I'm currently working on concerning a student record with guardians/parents... im using the java ee framework.. I'm having problems on retrieving the data on our database(MySQL).. Here is what i did.. i have created a class to retrieve those data from the database..
my problem is that whenever i retrieve that data in my jsp page, it only shows this Ljava.lang.String@123EGa something similar to this..
<small><br />
CLASS PLARENTS .. <br />
<br />
package com;<br />
import java.io.*;<br />
import java.sql.*;<br />
import javax.servlet.jsp.*;<br />
import javax.servlet.jsp.tagext.*;<br />
<br />
public class Parents {<br />
<br />
public String[] lastname;<br />
public String[] firstname;<br />
public String[] middlename;<br />
public String[] relation;<br />
<br />
private Connection connection = null;<br />
private Statement statement = null;<br />
private ResultSet rs = null;<br />
Connect con = new Connect();<br />
int count = 0;<br />
<br />
public Parents(){}<br />
<br />
public Parents(int idno) {<br />
int i = 0;<br />
try {<br />
Class.forName("com.mysql.jdbc.Driver").newInstance();<br />
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sis",con.user,con.password);<br />
statement = connection.createStatement();<br />
rs = statement.executeQuery("SELECT * FROM guardians WHERE studidno='" + idno + "'");<br />
<br />
if (rs.last()) {<br />
count = rs.getRow();<br />
}<br />
<br />
lastname = new String[count];<br />
firstname = new String[count];<br />
middlename = new String[count];<br />
relation = new String[count];<br />
<br />
while (rs.next()){<br />
lastname[i] = rs.getString("lastname");<br />
firstname[i] = rs.getString("firstname");<br />
middlename[i] = rs.getString("middlename");<br />
relation[i] = rs.getString("relation");<br />
i++;<br />
}<br />
<br />
} catch (Exception e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
<br />
public String[] getLastname(){return lastname;}<br />
<br />
public String[] getFirstname () {return firstname;}<br />
<br />
public String[] getMiddlename () {return middlename;}<br />
<br />
public String[] getRelation () {return relation;}<br />
<br />
}</small>
and this is what i placed in my jsp page..
<small> <% <br />
Parents p = new Parents(info.getIdno());<br />
for (int i = 0; i < p.getFirstname().length; i++ ) {<br />
%><br />
<tr bgcolor="#fefce3"><br />
<td><br />
<p id="info"><br />
<%= p.getLastname() %><br />
</p><br />
<p id="record">Relationship:<br />
<span id="relationship"><br />
<%= p.getFirstname() %><br />
</span><br />
</p><br />
</td><br />
<br />
</tr><br />
<tr><br />
<td> </td><br />
</tr><br />
>% } %></small>
Hi, I'm currently working on concerning a student record with guardians/parents... im using the java ee framework.. I'm having problems on retrieving the data on our database(MySQL).. Here is what i did.. i have created a class to retrieve those data from the database..
my problem is that whenever i retrieve that data in my jsp page, it only shows this Ljava.lang.String@123EGa something similar to this..
"according to what i have read on some searches, the best way to do it is by using data access objects..".. can anybody just an idea on how to do this using data access objects or give some sample codes for me to do this.. Im asking for an idea.. or any sample codes will do.. i have been working on this for about 2 days now, I've done so many researches and i haven't quite find any answer to my problem..
modified on Monday, October 27, 2008 9:23 PM
|
|
|
|
|
Hi,
I am a new member in this forum. I am developing a website.In my website once a user logs in, he is made to view a number of links, the click on which takes them to a new site.
suppose my site is x.com. x.com have a number of url, ome among is a.com. clicking on a.com should allow the user to access search page in a.com site. What i need is when a user clicks on the link a.com from my site x.com, he should be automatically logged into the a.com site. the login info, cookies etc should should be passed programmatically.
Can some one help me to implement this.
Thanks in advance
veda
|
|
|
|
|
Hi,
I have some problem in doing Jtable (I want the JTable to read the data from database) I wrote the code and it work with me in another project but Kow it didn't work I want some one to check this code if I miss some comma or thing in it.
The Code :
//=========================================
package Inventory;
public class cm1 {
private String tables;
public String selectData(String fields, String whereClause) {
if (whereClause == null && fields != null) {
return "SELECT " + fields + " FROM " + this.tables;
} else if (whereClause == null && fields == null) {
return " SELECT * FROM " + this.tables;
} else if (whereClause != null && fields == null) {
return " SELECT * FROM " + this.tables + " WHERE " + whereClause;
} else {
return "SELECT " + fields + " FROM " + this.tables + " WHERE "
+ whereClause;
}
}
//=========================================
public String deleteData(String whereClause) {
return "DELETE " + this.tables + " WHERE " + whereClause;
}
//=========================================
public void setDbTables(String table) {
this.tables = table;
}
//=========================================
public String insertQuery(AddPR p) {
return "INSERT INTO "
+ this.tables
+ " ( ITEMNUM,ITEMTYPE,LOCATION,MANUCODE,FXDASTNUM,MANUSRLNUM,COMMDATE,DESCRIPTION,STATUS,STATUSDATE,MODEL,MSRNUM,COMTYPE,USERNAME,TMSRV,PORT,IPADDRESS,PRICE,PRODUCTIONDATE,YEAR) VALUES ("+ p.getITEMNUM() + ", '" + p.getITEMTYPE() + "', '" + "', '" + p.getLOCATION() + "', '" + "','" + p.getMANUCODE() + "','" + p.getFXDASTNUM() + "', '" + p.getMANUSRLNUM() + "', '" + p.getCOMMDATE() + "', '" + p.getDESCRIPTION() + "', '" + p.getSTATUS() + "', '" + p.getSTATUSDATE() + "','" + p.getMODEL() + "','" + p.getMSRNUM() + "','" + p.getCOMTYPE() + "','" + p.getUSERNAME()+ "','" + p.getTMSRV() + "','" + p.getPORT()+ "','" + p.getIPADDRESS()+ "','" + p.getPRICE()+ "','" + p.getPRODUCTIONDATE() + "', '" +p.getYEAR();
}
}
//========================================="the end of the code"
please help me as soon as possible
|
|
|
|
|