How to make a oval shape in java
how to make an oval shape in java
here's a simple example:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
/* <applet code="OvalTest" width=83 height=43></applet> */
public class OvalTest extends Applet {
public void init() {
setBackground(Color.white);
public void paint(Graphics g) {
g.setColor(Color.blue);
g.fillOval(1,1,80,40);
}
Similar Messages
-
How can I change oval shape applet to (plot)
Hi this is not my code so, the orignal code is freeware to www.neuralsemantics.com and is Copyright 1989 by Rich Gopstein and Harris Corporation.
The site allows permission to play with the code or ammend it.
how could I modify the applet to display (plot) several cycles of the audio signal instead of the elliptical shape. The amplitude and period of the waveform should change in accordance with the moving sliders
Here is the code from www.neuralsemantics.com /applets/jazz.html
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class JazzMachine extends Applet
implements Runnable, AdjustmentListener, MouseListener {
// program name
final static String TITLE = "The jazz machine";
// Line separator char
final static String LSEP = System.getProperty("line.separator");
// Value range
final static int MIN_FREQ = 1; // min value for barFreq
final static int MAX_FREQ = 200; // max value for barFreq
final static int MIN_AMPL = 0; // min value for barVolume
final static int MAX_AMPL = 100; // max value for barVolume
// Sun's mu-law audio rate = 8KHz
private double rate = 8000d;
private boolean audioOn = false; // state of audio switch (on/off)
private boolean changed = true; // change flag
private int freqValue = 1; // def value of frequency scrollbar
private int amplValue = 70; // def value of volume scrollbar
private int amplMultiplier = 100; // volume multiplier coeff
private int frequency, amplitude; // the requested values
private int soundFrequency; // the actual output frequency
// the mu-law encoded sound samples
private byte[] mu;
// the audio stream
private java.io.InputStream soundStream;
// graphic components
private Scrollbar barVolume, barFreq;
private Label labelValueFreq;
private Canvas canvas;
// flag for frequency value display
private boolean showFreq = true;
// width and height of canvas area
private int cw, ch;
// offscreen Image and Graphics objects
private Image img;
private Graphics graph;
// dimensions of the graphic ball
private int ovalX, ovalY, ovalW, ovalH;
// color of the graphic ball
private Color ovalColor;
// default font size
private int fontSize = 12;
// hyperlink objects
private Panel linkPanel;
private Label labelNS;
private Color inactiveLinkColor = Color.yellow;
private Color activeLinkColor = Color.white;
private Font inactiveLinkFont = new Font("Dialog", Font.PLAIN, fontSize);
private Font activeLinkFont = new Font("Dialog", Font.ITALIC, fontSize);
// standard font for the labels
private Font ctrlFont;
// standard foreground color for the labels
private Color fgColor = Color.white;
// standard background color for the control area
private Color ctrlColor = Color.darkGray;
// standard background color for the graphic ball area
private Color bgColor = Color.black;
// start value for the time counter
private long startTime;
// maximum life time for an unchanged sound (10 seconds)
private long fixedTime = 10000;
// animation thread
Thread runner;
// Constructors
public JazzMachine() {
// Methods
public void init() {
// read applet <PARAM> tags
setAppletParams();
// font for the labels
ctrlFont = new Font("Dialog", Font.PLAIN, fontSize);
// convert scrollbar values to real values (see below for details)
amplitude = (MAX_AMPL - amplValue) * amplMultiplier;
frequency = (int)Math.pow(1.2d, (double)(freqValue + 250) / 10.0);
setLayout(new BorderLayout());
setBackground(ctrlColor);
setForeground(fgColor);
Label labelVolume = new Label(" Volume ");
labelVolume.setForeground(fgColor);
labelVolume.setAlignment(Label.CENTER);
labelVolume.setFont(ctrlFont);
barVolume = new Scrollbar(Scrollbar.VERTICAL, amplValue, 1,
MIN_AMPL, MAX_AMPL + 1);
barVolume.addAdjustmentListener(this);
// assign fixed size to the scrollbar
Panel pVolume = new Panel();
pVolume.setLayout(null);
pVolume.add(barVolume);
barVolume.setSize(16, 90);
pVolume.setSize(16, 90);
Label labelFreq = new Label("Frequency");
labelFreq.setForeground(fgColor);
labelFreq.setAlignment(Label.RIGHT);
labelFreq.setFont(ctrlFont);
barFreq = new Scrollbar(Scrollbar.HORIZONTAL, freqValue, 1,
MIN_FREQ, MAX_FREQ);
barFreq.addAdjustmentListener(this);
// assign fixed size to the scrollbar
Panel pFreq = new Panel();
pFreq.setLayout(null);
pFreq.add(barFreq);
barFreq.setSize(140, 18);
pFreq.setSize(140, 18);
// show initial frequency value
labelValueFreq = new Label();
if (showFreq) {
labelValueFreq.setText("0000000 Hz");
labelValueFreq.setForeground(fgColor);
labelValueFreq.setAlignment(Label.LEFT);
labelValueFreq.setFont(ctrlFont);
Panel east = new Panel();
east.setLayout(new BorderLayout(10, 10));
east.add("North", labelVolume);
Panel pEast = new Panel();
pEast.add(pVolume);
east.add("Center", pEast);
Panel south = new Panel();
Panel pSouth = new Panel();
pSouth.setLayout(new FlowLayout(FlowLayout.CENTER));
pSouth.add(labelFreq);
pSouth.add(pFreq);
pSouth.add(labelValueFreq);
south.add("South", pSouth);
linkPanel = new Panel();
this.composeLink();
Panel west = new Panel();
// dummy label to enlarge the panel
west.add(new Label(" "));
add("North", linkPanel);
add("South", south);
add("East", east);
add("West", west);
add("Center", canvas = new Canvas());
private void composeLink() {
linkPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
linkPanel.setFont(inactiveLinkFont);
linkPanel.setForeground(Color.yellow);
Label labelName = new Label(TITLE + " \u00a9");
labelName.setForeground(inactiveLinkColor);
labelName.setAlignment(Label.RIGHT);
labelNS = new Label(" Neural Semantics ");
labelNS.setForeground(inactiveLinkColor);
labelNS.setFont(inactiveLinkFont);
labelNS.setAlignment(Label.LEFT);
linkPanel.add(labelName);
linkPanel.add(labelNS);
// link to Neural Semantics website
String h = getDocumentBase().getHost();
if ((h.length() > 4) && (h.substring(0, 4).equals("www.")))
h = h.substring(4);
if ((h != null) && (! h.startsWith("neuralsemantics.com"))) {
// create a hand cursor for the hyperlink area
Cursor linkCursor = new Cursor(Cursor.HAND_CURSOR);
linkPanel.setCursor(linkCursor);
labelName.addMouseListener(this);
labelNS.addMouseListener(this);
private void switchAudio(boolean b) {
// switch audio to ON if b=true and audio is OFF
if ((b) && (! audioOn)) {
try {
sun.audio.AudioPlayer.player.start(soundStream);
catch(Exception e) { }
audioOn = true;
// switch audio to OFF if b=false and audio is ON
if ((! b) && (audioOn)) {
try {
sun.audio.AudioPlayer.player.stop(soundStream);
catch(Exception e) { }
audioOn = false;
private void getChanges() {
// create new sound wave
mu = getWave(frequency, amplitude);
// show new frequency value
if (showFreq)
labelValueFreq.setText((new Integer(soundFrequency)).toString() + " Hz");
// shut up !
switchAudio(false);
// switch audio stream to new sound sample
try {
soundStream = new sun.audio.ContinuousAudioDataStream(new
sun.audio.AudioData(mu));
catch(Exception e) { }
// listen
switchAudio(true);
// Adapt animation settings
double prop = (double)freqValue / (double)MAX_FREQ;
ovalW = (int)(prop * cw);
ovalH = (int)(prop * ch);
ovalX = (int)((cw - ovalW) / 2);
ovalY = (int)((ch - ovalH) / 2);
int r = (int)(255 * prop);
int b = (int)(255 * (1.0 - prop));
int g = (int)(511 * (.5d - Math.abs(.5d - prop)));
ovalColor = new Color(r, g, b);
// start the timer
startTime = System.currentTimeMillis();
// things are fixed
changed = false;
// Thread
public void start() {
// create thread
if (runner == null) {
runner = new Thread(this);
runner.start();
public void run() {
// infinite loop
while (true) {
// Volume or Frequency has changed ?
if (changed)
this.getChanges();
// a touch of hallucination
repaint();
// let the children sleep. Shut up if inactive during more
// than the fixed time.
if (System.currentTimeMillis() - startTime > fixedTime)
switchAudio(false);
// let the computer breath
try { Thread.sleep(100); }
catch (InterruptedException e) { }
public void stop() {
this.cleanup();
public void destroy() {
this.cleanup();
private synchronized void cleanup() {
// shut up !
switchAudio(false);
// kill the runner thread
if (runner != null) {
try {
runner.stop();
runner.join();
runner = null;
catch(Exception e) { }
// AdjustmentListener Interface
public void adjustmentValueChanged(AdjustmentEvent e) {
Object source = e.getSource();
// Volume range : 0 - 10000
// ! Scrollbar value range is inverted.
// ! 100 = multiplier coefficient.
if (source == barVolume) {
amplitude = (MAX_AMPL - barVolume.getValue()) * amplMultiplier;
changed = true;
// Frequency range : 97 - 3591 Hz
// ! Scrollbar value range represents a logarithmic function.
// The purpose is to assign more room for low frequency values.
else if (source == barFreq) {
freqValue = barFreq.getValue();
frequency = (int)Math.pow(1.2d, (double)(freqValue + 250) / 10.0);
changed = true;
// MouseListener Interface
public void mouseClicked(MouseEvent e) {
public void mouseEntered(MouseEvent e) {
// text color rollover
labelNS.setForeground(activeLinkColor);
labelNS.setFont(activeLinkFont);
showStatus("Visit Neural Semantics");
public void mouseExited(MouseEvent e) {
// text color rollover
labelNS.setForeground(inactiveLinkColor);
labelNS.setFont(inactiveLinkFont);
showStatus("");
public void mousePressed(MouseEvent e) {
try {
java.net.URL url = new java.net.URL("http://www.neuralsemantics.com/");
AppletContext ac = getAppletContext();
if (ac != null)
ac.showDocument(url);
catch(Exception ex){ }
public void mouseReleased(MouseEvent e) {
// Painting
public void update(Graphics g) {
Graphics canvasGraph = canvas.getGraphics();
if (img == null) {
// get canvas dimensions
cw = canvas.getSize().width;
ch = canvas.getSize().height;
// initialize offscreen image
img = createImage(cw, ch);
graph = img.getGraphics();
// offscreen painting
graph.setColor(bgColor);
graph.fillRect(0, 0, cw, ch);
graph.setColor(ovalColor);
graph.fillOval(ovalX, ovalY, ovalW, ovalH);
// canvas painting
if (canvasGraph != null) {
canvasGraph.drawImage(img, 0, 0, canvas);
canvasGraph.dispose();
// Sound processing
// Creates a sound wave from scratch, using predefined frequency
// and amplitude.
private byte[] getWave(int freq, int ampl) {
int lin;
// calculate the number of samples in one sinewave period
// !! change this to multiple periods if you need more precision !!
int nSample = (int)(rate / freq);
// calculate output wave frequency
soundFrequency = (int)(rate / nSample);
// create array of samples
byte[] wave = new byte[nSample];
// pre-calculate time interval & constant stuff
double timebase = 2.0 * Math.PI * freq / rate;
// Calculate samples for a single period of the sinewave.
// Using a single period is no big precision, but enough
// for this applet anyway !
for (int i=0; i<nSample; i++) {
// calculate PCM sample value
lin = (int)(Math.sin(timebase * i) * ampl);
// convert it to mu-law
wave[i] = linToMu(lin);
return wave;
private static byte linToMu(int lin) {
int mask;
if (lin < 0) {
lin = -lin;
mask = 0x7F;
else {
mask = 0xFF;
if (lin < 32)
lin = 0xF0 | 15 - (lin / 2);
else if (lin < 96)
lin = 0xE0 | 15 - (lin-32) / 4;
else if (lin < 224)
lin = 0xD0 | 15 - (lin-96) / 8;
else if (lin < 480)
lin = 0xC0 | 15 - (lin-224) / 16;
else if (lin < 992)
lin = 0xB0 | 15 - (lin-480) / 32;
else if (lin < 2016)
lin = 0xA0 | 15 - (lin-992) / 64;
else if (lin < 4064)
lin = 0x90 | 15 - (lin-2016) / 128;
else if (lin < 8160)
lin = 0x80 | 15 - (lin-4064) / 256;
else
lin = 0x80;
return (byte)(mask & lin);
// Applet info
public String getAppletInfo() {
String s = "The jazz machine" + LSEP + LSEP +
"A music synthetizer applet" + LSEP +
"Copyright (c) Neural Semantics, 2000-2002" + LSEP + LSEP +
"Home page : http://www.neuralsemantics.com/";
return s;
private void setAppletParams() {
// read the HTML showfreq parameter
String param = getParameter("showfreq");
if (param != null)
if (param.toUpperCase().equals("OFF"))
showFreq = false;
// read the HTML backcolor parameter
bgColor = changeColor(bgColor, getParameter("backcolor"));
// read the HTML controlcolor parameter
ctrlColor = changeColor(ctrlColor, getParameter("controlcolor"));
// read the HTML textcolor parameter
fgColor = changeColor(fgColor, getParameter("textcolor"));
// read the HTML fontsize parameter
param = getParameter("fontsize");
if (param != null) {
try {
fontSize = Integer.valueOf(param).intValue();
catch (NumberFormatException e) { }
private Color changeColor(Color c, String s) {
if (s != null) {
try {
if (s.charAt(0) == '#')
c = new Color(Integer.valueOf(s.substring(1), 16).intValue());
else
c = new Color(Integer.valueOf(s).intValue());
catch (NumberFormatException e) { e.printStackTrace(); }
return c;
}thanks LIZ
PS If you can help how do I Give the Duke dollers to youhttp://www.google.ca/search?q=java+oval+shape+to+plot&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=10&sa=N
Ask the guy who made it for more help -
How to create a oval shape JButton?
Dear All,
Can you please tell me how to create an Oval shaped Jbutton. Please send me code if possible.
Regards,
SatYou can check out the Substance look-and-feel project at:
https://substance.dev.java.net/
https://substance-button-shaper-pack.dev.java.net/
A substance plugin is also available for NetBeans:
http://www.netbeans.org/kb/50/substance-look-and-feel.html -
How to make a net browser using java
We want to make an MultiLingual Explorer in JAVA .So please help me in the case thatfirst i want to do the coding of the basic interface as the menu option like open,save,save As etc.So how can i start it in java.Is their any builtin support or what is the best possible ways.I sahll appreciate the cooperation....
Kindly help me out....
(As i am a student and new in java so plz guide me thoroughly)
ThanxThere have been java browsers that have been developed + this is well-documented (at least in one or two texts i've read, i assume on-line too), but they're quite complex + i doubt if someone new to java would be able to customise it without a brain haemorrhage. Tough call!
-
Using PS CS 6 how to make an oval gradient
I just want to make a gradient, transparent to black, like a vignette only more so, on an image that is four times as wide as high. I can make a circular gradient, and start it at the centre using the ALT key, but I can't make it oval. I'm using PS CS 6, Win 7x64.
I know this is simple, I even used to know how to do it, but the brain isn't responding. Can someone tell me what I'm missing?
DavidBegin with the radial gradient (Step 1)
Select the area shown in Step 2)
Edit > Transform > Distort (Step 3)
Image > Adustments > Invert (Step 4, is desired) -
How to make file associations in my java apps
I am making a Graph maker in Java. Just give x = 1,2,3,4,5 and corresponding y = f(x) and get the discreate graph.
The graph can then be saved as a file of extention .grf (say) on the hard disk, and can be opened in my graph maker software for editing, viewing e.t.c.
Now my problem is that I want that when I dubble click on a file xyz.grf my graph maker should open automatically with this file opened in it, like other applications on windows say Notepad - dubble click on xyz.txt it will automatically launch Notepade with this file.
In other way I want that any .grf file gets associated to my graf maker.
Please help me and tell me the way, how should I proceed and how can I do this.aashishjava wrote:
Yes Yes Yes It is 99% what I wanted to have. Thanks a lot ....You're welcome.
But now I want some thing more,(hand to forehead) They always want more. ;)
(a) There is a splash screen in my app. but JNLP always show its own splash screen, ...Webstart splash screens work differently to those of plain Jar files (which is unfortunate). A webstart splash screen has to be not included in the Jar, but available as a separate resource. The splash is defined in the JNLP launch file. For further details see the [JNLP File Syntax|http://java.sun.com/j2se/1.4.2/docs/guide/jws/developersguide/syntax.html].
<quote>
The optional kind="splash" attribute may be used in an icon element to indicate that the image is to be used as a "splash" screen during the launch of an application. If the JNLP file does not contain an icon element with a kind="splash" attribute, but does contain another icon tag, Java Web Start will display a splash screen consisting of the image specified by the icon element on the left and the application's title and vendor on the right.
The first time an application is launched following the addition or modification of the icon element in the JNLP file, the old splash image will still be displayed. The new splash image will appear on the second and subsequent launches of the application.
</quote>
The 'ignored first time' is because the webstart client is more focused on getting the app. downloaded, cached and launched, than showing splashes. Once the app. is on-screen, it will download the splash in the background.
One other 'gotcha' of splash screens is that the JNLP file must define a href in the JNLP element for the splash to be used. The webstart client assumes that a JNLP with no href is dynamically generated, and will not be the same twice. Because of that it ignores the splash!
Edit 1:
Unfortunately, I do not have any direct examples of using splash screens A splash is usually on my 'To Do' list for projects, but it is a very low priority.
Edited by: AndrewThompson64 on Dec 10, 2009 11:35 AM -
How to make a horizontal line in java html browser?? without hr
I use java html browser
I want to make a black horizontal line
the <hr> line is not good
for my customer it seems that there is a double spacing in this case
I tried to write
<td style = "BORDER-BOTTOM: 1px solid #000000"> ...
but it does not work
I suppose this style is not supported by the default StyleSheet
I tried to write
<td bgcolor="black" height=1>
but the table has all rows with equal sizes
therefore the real height is too big
Please help me
I tried to write
<table border="1">... </table>
even in this case I have table without any borderHi,
the best way might be to use a blind table with all cells set to have a border on the bottom. The problem is that the standard Java runtime does not render such setting automatically. There is plenty of work involved to adapt it and still it then would work only in the adapted version and not the standard runtime environment.
Anyway, you can find a working example of how to accomplish individual borders around table cells in open source application SimplyHTML at http://www.lightdev.com/dev/sh.htm
Ulrich -
How To Make A File Splitter In Java
Hey everyone...is it possible to make a file splitter program in java swing?what API do you think should be used in creating that application and how does it work? Assume that the application will be ran on windows desktop. Thanks to all...
* FileSplitter.java
import java.util.*;
public class FileSplitter {
ArrayList list = new ArrayList();{
list.add("test 01");
list.add("test 02");
list.add("test 03");
list.add("test 04");
list.add("test 05");
list.add("test 06");
list.add("test 07");
list.add("test 08");
list.add("test 09");
list.add("test 10");
list.add("test 11");
list.add("test 12");
list.add("test 13");
list.add("test 14");
list.add("test 15");
list.add("test 16");
list.add("test 17");
list.add("test 18");
list.add("test 19");
list.add("test 20");
list.add("test 21");
list.add("test 22");
list.add("test 23");
list.add("test 24");
list.add("test 25");
list.add("test 26");
list.add("test 27");
list.add("test 28");
list.add("test 29");
list.add("test 30");
public FileSplitter() {
testAlgorithm();
private void testAlgorithm(){
final int randNo = list.size()/2;//=number of input records / 2
Random r = new Random(); //creates a new random number generator
List newlist = new ArrayList(); //constructs a new empty list
while(list.size()> randNo) {//returns true if the number of elements in the list is greater than randNo
//(half of the input records are splitted)
int index = r.nextInt(list.size());//returns a random between 0 (inclusive)
//and the number of elements in the list (exclusive)
newlist.add(list.get(index));//returns the element at the specified position in the list
//and appends it to the end of newlist
list.remove(index);//removes the element at the specified position in the list
//and shifts any subsequent elements to the left
System.out.println("newlist: "+newlist);//one part of the file
System.out.println("list: "+list);//the other part of throws file
public static void main(String[] args) {
new FileSplitter();
} -
How to make a Exception class in java ?
I want to make a class called SomeException. I want to throw this exception from my class Myclass. How to do it ??
Just let SomeException extend Exception (or RuntimeException) and throw it the same way you'd throw any other exception. There's no magic involved.
-
How to make a modular program in java
hello friends,
i want to know that how i can make my program in a modular way.
Thanks in advance
Rakeshhello sir,
thanks to notice me.
modular program means, i have a large program which contains about 1500 lines. now i want to subdivide this program in multiple files and after call all files in a single main file . and want to run overall program from a single main file.
regards,
Rakesh -
How to make a WSDL file generate Java Code
Hi, I'm quite new in web services. I used the ebay shopping service importing the WSDL file with wsimport, and NetBeans automagically created the Ebay libraries while parsing the WSDL.
Now I'm trying to implement my own soap WS, i'm quite finished but when I try to use it importing the WSDL in a new project, my classes are not imported.
So, where's the trick? How can I include code generationi n my WSDL?
thanks in advance :)hi,
since the wsdl parsing was complet, for sure the classes are copied (.java), to see them check the following path
YourService\build\generated\wsimport\client\YourService
and the .class file will be in
YourService\build\generated\wsimport\binaries\YourService -
How to make Visibroker's 'vbjc' use Java 1.3 by modifying the properties fi
Hi,
I am using Visibroker for java 4.0 to develop an application. The
java version that I am using is 1.4.1. Now, the naming service does
not start when I use 1.4.1. And I cannot do away with Java1.4.1
because I am using certain classes in javax.crypto which does not
exist at all in Java 1.3. I am left with the option of trying to
configure the properties file of 'vbjc' in such a way that it uses
Java 1.3 instead of 1.4. How can i do this? Can someone please help me
out?
Thanks in advance,
Shankar.HI!
you hasn't given more details ;
can you send me the command, by which you r trying to start the Naming service.
As well as send me the error that you are getting , when used jdk1.4.1 -
How to make a setup file in java
I have a softwave writting in java . I want to create a setup file.
Please help me . thankshttp://forum.java.sun.com/thread.jsp?forum=54&thread=422117&tstart=0&trange=15
This should answer 99.9% of your questions. In addition you may want to look into how to create Executable Jar files. -
How to make bank management system using java file system
Hi, I have some fields
1.ID
2. Deposite
3. Withdraw
4. Balance
Now how can i manage this Bank Management System using java file system.
Thanks in advance.Then we're back to (1): Do your own homework. Google has zillions of links on handling files in Java. When you have written some code and have an actual problem, we'll be happy to help you with it.
(edit) Incidentally, this sounds suspiciously like the sort of problem they set for the certification programs. In which case, don't bother; they're not worth the virtual paper they're printed on. -
How to make a .exe from a java .class
Hi All,
I want to write a scheduler program in Java and that class file I want to install as a service in windows scheduler. So for that purposr I need an executale right?
How can I convert a java class to a .exe program.
Thanks and Regards
KKNo need to create exe file. U can covert into .bat file. With help of windows scheduler u can run the file as per ur required.
Maybe you are looking for
-
iPhone will not connect to my iTunes. I am running iTunes version 10.6.3 on my iMac runing Mac OS X version 10.5.8. All of my updates say "up to date" but this is obviously not the case. Can anyone help me out?
-
Audigy partly not working in XP - now "disappear
I have an Audigy in an AMD64 PC. Dual boot - Linux (suse) no problems XP - no wave sound, midi OK. Mixer and speaker test in Creating HQ fail to start. Driver update - no hardware detected. Diagnostics - hardware OK, midi OK, wav fail, mixer fail. Tr
-
My sound stopped working after installing Java
my sound stopped working after installing Java
-
Hello. Apple hardware test has detected an error. 4SNS/1/40000001:TN1D--1.000 Anyone knows what that means ? OS doesn't boot. Maybe it's hard disk error ?
-
MacBook not working when modified from stock config
I have an Aluminum MacBook that came with 2 gigs of ram and a 250 gig hard drive. When trying to upgrade either the ram or the hard drive, the machine has problems booting and regardless of what I try, it will not accept Snow Leopard. SL will install