[Show all top banners]

marconi
Replies to this thread:

More by marconi
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java Help needed
[VIEWED 2200 TIMES]
SAVE! for ease of future access.
Posted on 03-27-07 12:22 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Can anyone provide me code for a very simple java applet GUI? I need it in GUI applet and should have a button. When the button is clicked, a line should be drawn somewhere in there.

Please provide help, i m just learning java and need it urgently.....
 
Posted on 03-27-07 1:05 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.Object.*;

public class ProblemB {
static int Counter ;

static int windowWidth;
static int windowHeight;

// FOUR WINDOW CORNERS
static int x1;
static int y1;

static int x2;
static int y2;

static int x3;
static int y3;

static int x4;
static int y4;

static boolean flag;
static int T1;
// Diagonal Point
static int diagonalPointX;
static int diagonalPointY;
static int triangle1Y1;
static int triangle1Y2;
static class MyFrame extends JFrame {
public void paint (Graphics g) {
super.paint(g);
System.out.println("printing " + Counter);
if (flag){
g.setColor(Color.BLUE);
}
else {
g.setColor(Color.BLACK);
}

g.drawString( new Integer (Counter).toString(),50,50);


g.drawLine( 5, 30, windowWidth-5,windowHeight-2 );
g.drawLine(5,windowHeight-2, windowWidth-5, 30 );
}
}

static MyFrame frame;

public static void main (String[] args) {
windowWidth = 200; // Default window Width
windowHeight = 200; // Default Window Height

frame = new MyFrame ();

Dimension Size = new Dimension (windowWidth,windowHeight);
//Vec2d[] Vertex1 = new Vec2d[100];
class MyAdapter extends MouseAdapter {

public void mouseClicked (MouseEvent e) {
Counter++;
if (Counter%2==0) {
flag = true;
}
else {
flag = false;
}
frame.repaint();
x1 = 5;
y1 = 30;

x2 = windowWidth-5 ;
y2 = 30;

x3 = windowWidth;
y3 = windowHeight-2;

x4 = 0;
y4 = windowHeight-2;

// Diagonal Point
diagonalPointX = (x1+x3)/2 ;
diagonalPointY = (y1+y3)/2;

// System.out.println(diagonalPointX +","+diagonalPointY);
Point x_y = new Point(e.getX(),e.getY());
// System.out.println(" point " +x_y);

// swcond point on diagonal 1
triangle1Y1 = (((y3-y1)/(x3-x1))*(x2-x1))+y1;
triangle1Y2 = (((y4-y2)/(x4-x2))*(x1 -x2))+y2;

if(triangle1Y1 if(e.getY() T1++;
}
}
if(triangle1Y1>y2){
if(e.getY()>y2){
T1++;
}
}
if(triangle1Y2 if(e.getY() T1++;
}
}
if(triangle1Y2>y1){
if(e.getY()>y1){
T1++;
}
}
System.out.println(triangle1Y1+" "+triangle1Y2);
if(T1==2){
System.out.println("The point is inside triangle 1.");
}
T1=0;
}
}

class MyWindowAdapter extends WindowAdapter {
public void windowClosing (WindowEvent e) {

System.exit(0);
}
}
class MyComponentAdapter extends ComponentAdapter {
public void componentResized(ComponentEvent e) {
windowHeight = frame.getSize().height;
windowWidth = frame.getSize().width;
frame.repaint();
}
}

MyAdapter MyAdapterObject = new MyAdapter();

MyWindowAdapter MyWindowAdapterObject = new MyWindowAdapter();
MyComponentAdapter MyComponentAdapterObject = new MyComponentAdapter();

Counter = 0;
T1=0;
x1 = 5;
y1 = 30;

x2 = windowWidth-5 ;
y2 = 30;

x3 = windowWidth;
y3 = windowHeight-2;

x4 = 0;
y4 = windowHeight-2;
triangle1Y1 = 0;
triangle1Y2 = 0;

flag =false;
// Diagonal Point
diagonalPointX = (x1+x3)/2 ;
diagonalPointY = (y1+y3)/2;

frame.addMouseListener(MyAdapterObject);
frame.addWindowListener (MyWindowAdapterObject);
frame.addComponentListener (MyComponentAdapterObject);
frame.setSize(Size);
frame.setVisible(true);
}
}
--------------------------------------------------------------------------------------------------

Edit the code to what you want from it.
 
Posted on 03-27-07 1:09 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

wow... just to draw a line in a click this many codes....damn...
then java must be hard..:-)
 
Posted on 03-27-07 1:23 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Its just a single line to draw a line which is
------------------
g.drawLine( 5, 30, windowWidth-5,windowHeight-2 );
----------------------------

The rest of the code is to set up the GUI. There are many lines of unwanted code in that program . I just copy pasted one of my assignments which has the part that marconi needs..
 
Posted on 03-27-07 11:10 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 03-27-07 11:18 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

hmm..anyone downloaded that program Netbeans 5.0? I can't find the 'Design' and 'Source' button/page. It was there before, but I did something...ani kata gaayo. Anyone know how to bring it back in the software again? HELP..PEEELEESE!
 
Posted on 03-27-07 11:33 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Try View -> Show Editor Toolbar.
 
Posted on 03-28-07 12:20 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

oooh! I got it now. Republican, chaina 'view' ma. I had to create a Project first and then right click on the project to open up the JFrame. Durr..hmm..how am I gonna complete other stuff yesto saano kura paani naa aako..hehe.
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
ChatSansar.com Naya Nepal Chat
सालीको चाक
Conservative discussions
Looking for girl
tesla stock OMG !!
TPS for Nepal likely to extend next week
Who is hottest nepali female?
Toilet paper or water?
TPS To F-1 COS
I hope all the fake Nepali refugee get deported
Those who are in TPS, what’s your backup plan?
Nepal TPS has been Extended !!!
ढ्याउ गर्दा दसैँको खसी गनाउच
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
Homeland Security revokes temporary status for 532,000 Cubans, Haitians, Nicaraguans and Venezuelans
Venezuela TPS lawuit
Embassy of Nepal might be able to help extend TPS for Nepal
Tourist Visa - Seeking Suggestions and Guidance
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
Looking for girl
Who is hottest nepali female?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters