|
I Googled.I just want to ask that kind of dynamic task bar(remove and zoom)is maked by what kind of control.For example:rectangle or lable.Our Project id based Swing.Please help me.
|
|
|
|
|
please tell me the code to calculate the practical numbers in a given range..
|
|
|
|
|
rics 2 wrote: please tell me the code to calculate the practical numbers in a given range..
You need to learn to do your own work, not expect others to do it for you. If you then encounter a problem in your code you can post a specific question here.
If you have absolutely no idea of the algorithm for practical numbers then you can use any of the internet search engines; Google yields some interesting hits.
|
|
|
|
|
If you understand this then you can code it:
In mathematics, and in particular number theory, a practical number or panarithmic number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n. For example, 12 is a practical number because all the numbers from 1 to 11 can be expressed as sums of its divisors 1, 2, 3, 4, and 6: as well as these divisors themselves, we have 5=3+2, 7=6+1, 8=6+2, 9=6+3, 10=6+3+1, and 11=6+3+2.
Source: Wiki[^]
|
|
|
|
|
|
I need to know if I have successfully created a Square Matrix List of Entry Objects. The detail desciption and my java code solution follows:
A) Description
1) The List ADT will export its services to the Matrix ADT.
2) The List ADT will defines a List of Objects. The Objects referred to by these List elements will be defined in the Matrix ADT
3) The Matrix ADT, in file Matrix.java, defines the Matrix class. This class will contain a private inner class that encapsulates the column and value information corresponding to a matrix entry.
B) Code
List.java
class List
{
private class Node
{ Object obj;
Node next, prev;
// Node Constructor
Node (Object o) { this.obj = o; next = prev = null; }
// toString: Overrides object's toString method.
public String toString() { return String.valueOf(obj); }
}
// List Fields
private Node front, back, current;
private int row, length;
// List Constructor
List(int r)
{ front = back = current = null;
this.row = r; this.length = 0;
}
}
Matrix.java
class Matrix
{
private class Entry
{ int col;
double val;
// Entry Constructor
Entry (int col, double val) { this.col = col; this.val = val; }
// toString: Overrides Object's toString() method.
public String toString() { return " (" + col + ", " + val + ")"; }
}
// Matrix Fields
private List[] Entry;
private int size, nnz;
// Matrix Constructor
Matrix(int n) { Entry = new List[n]; this.size = n; nnz = 0; }
}
|
|
|
|
|
|
I am beginner to java.so please bring me any small applet programs to do.
Just give me the concept.I will try coding myself...
|
|
|
|
|
Here[^] is a good java applet tutorial for beginners. You will find 4 chapters with examples. The code is well commented, but only the basics of applet programming are covered. Anyway, I think that this is a good "learn by examples" tutorial for Java applets.
I hope this helps you.
Nuri Ismail
|
|
|
|
|
Thank you its realy helpful
|
|
|
|
|
can someone help! I am working with graphics primitives and I am having a problem in creating 5 drawings in 5 rectangular regions within one window.The following is what i have managed to come up with.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class Circleline extends JApplet{
int x=300,y=100,r=50;
int xPoints[] = {50,80,80,50,50}; //Sets x coordinates to draw to/from
int yPoints[] = {50,50,80,80,50}; //Sets y coordinates to draw to/from
public void paint(Graphics Obj,Graphics g) //paint function (essential for graphics)
{
Obj.setColor(Color.black); //Sets the color to green
Obj.fillPolygon(xPoints,yPoints,xPoints.length); //Uses the x,y coordinates declared earlier to draw a filled square
for(int i = 0; i < xPoints.length;i++) //for loop to add to x values to move it across screen
xPoints[i] += 200;
Obj.drawPolyline(xPoints,yPoints,xPoints.length); //draws an empty square at the new x values and same y values
}
public void paint(Graphics g){
g.drawLine(3,300,200,10);
g.drawString("Line",100,100);
g.drawOval(x-r,y-r,100,100);
g.setColor(Color.blue);
g.fillOval(x-r,y-r,100,100);
g.setColor(Color.magenta);
g.drawString("Circle",275,100);
g.fillRect(400,50,200,100);
g.setColor(Color.pink);
g.drawRect(400,50,200,100);
g.drawString("Rectangle",450,100);
g.setColor(Color.yellow);
g.drawRect(250,250,250,250);
g.fillRect(250,250,250,250);
g.setColor(Color.gray);
g.drawString("Square",350,350);
}
public void init() //Initialize
{
setBackground(Color.cyan); //Make window background cyan
setSize(400,400); //Set window size
}
}
Please help me so that the code can output 5 drawings in 5 rectangular regions within one window. Thank you
|
|
|
|
|
First you need to specify the regions for example region one is from (0,0), (0,100), (100,0), and (100,100) then when your drawing you should assign the drawings within the range of those region. Do note that you also need to use the frame size coordinates for a better view i.e. all the drawings will be viewed when you launch the application plus when you resize the frame the drawings will also resize.
|
|
|
|
|
Thank you for your answer. If you don't mind can you write for the code of doing what you mentioned above, I will appreciate so much. Thank you
|
|
|
|
|
The basic idea is
Dimension d = getSize();
int x = (int)d.getWidth();
int y = (int)d.getHeight();
g.drawLine(5, 5, x/10, y/10);
g.drawRect(5, 5, x/10, y/10);
g.fillRect(5+x/10+5+3, 5+3, x/10-6, y/10-10);
g.drawRect(5+x/10+5, 5, x/10, y/10);
g.drawOval(5+x/10+5+x/10+5+1, 5+1, x/10-6, y/10-10);
g.drawRect(5+x/10+5+x/10+5, 5, x/10, y/10);
|
|
|
|
|
Thank you for your support i appreciate so much. This is how I am trying to arrange the code, but it's not running.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class Circleline extends JApplet{
int x=300,y=100,r=50;
int xPoints[] = {50,80,80,50,50};
int yPoints[] = {50,50,80,80,50};
public void paint(Graphics Obj,Graphics g)
{
Obj.setColor(Color.black);
Obj.fillPolygon(xPoints,yPoints,xPoints.length);
for(int i = 0; i < xPoints.length;i++)
xPoints[i] += 200;
Obj.drawPolyline(xPoints,yPoints,xPoints.length);
}
public void paint(Graphics g){
g.drawLine(3,300,200,10);
g.drawString("Line",100,100);
g.drawOval(x-r,y-r,100,100);
g.setColor(Color.blue);
g.fillOval(x-r,y-r,100,100);
g.setColor(Color.magenta);
g.drawString("Circle",275,100);
g.fillRect(400,50,200,100);
g.setColor(Color.pink);
g.drawRect(400,50,200,100);
g.drawString("Rectangle",450,100);
g.setColor(Color.yellow);
g.drawRect(250,250,250,250);
g.fillRect(250,250,250,250);
g.setColor(Color.gray);
g.drawString("Square",350,350);
d = getSize();
int x = (int)
d.getWidht();
int y=(int)
d.getHeight();
g.drawLine
(5,5,x/10,y/10);
g.drawRect
(5,5,x/10,y/10);
g.fillRect
(5+x/10+5+3,x/10-6,y/10-10);
g.drawRect
(5+x/10+5,5,x/10,y/10);
g.drawOval
(5+x/10+5+x/10+5+1,5+1,x/10-6,y/10-10);
g.drawRect
(5+x/10+5+x/10+5,5,x/10,y/10);
}
public void init()
{
setBackground(Color.cyan);
setSize(400,400);
}
}
I will appreciate so much if you help to arrange the code. Thank you
|
|
|
|
|
of course it wont run if you have typo errors use Netbeans or Eclipse. Plus in your paint method I want you to copy the code in my previous post and replace from d.getsize() to the last g.drawrect(). This will run for sure.
|
|
|
|
|
I appreciate so much for your concern. Thank you so much.
I am using JCreator to compile my code. Still it's not running. Do I just copy the code without changing any thing? and where do I copy the code please help me I am new in java programming.
|
|
|
|
|
Dude, my previous post was crystal clear, Use Eclipse or Netbeans not any other IDE.
Paste this code and run:
import java.awt.*;
import javax.swing.*;
public class Circleline extends JApplet
{
public void paint(Graphics g)
{
Dimension d = getSize();
int x = (int) d.getWidth();
int y = (int) d.getHeight();
g.drawLine(5, 5, x / 10, y / 10);
g.drawRect(5, 5, x / 10, y / 10);
g.fillRect(5 + x / 10 + 5 + 3, 5 + 3, x / 10 - 6, y / 10 - 10);
g.drawRect(5 + x / 10 + 5, 5, x / 10, y / 10);
g.drawOval(5 + x / 10 + 5 + x / 10 + 5 + 1, 5 + 1, x / 10 - 6,y / 10 - 10);
g.drawRect(5 + x / 10 + 5 + x / 10 + 5, 5, x / 10, y / 10);
}
public void init()
{
setSize(400, 400);
}
}
|
|
|
|
|
Thank you very much now the code is working. I want to add some colors and text how do I do it? Thank you very much.
|
|
|
|
|
how about you read the code you supplied it already answers your question.
|
|
|
|
|
I am currently writing a Dungeons & Dragons Session tool for my final project in my Java class. So far I have the GUI drawn up EXCEPT for one ridiculous problem. For three of my JPanels, named panelNorth, PanelSouth, and guiWrapper, I CANNOT seem to set the background color for them. The first block of code is my driver and the second is the gui class for my program. Can anybody see why it will not set the background color for those 3 specific panels???
p.s. the button listened is commented out because I just want to get the gui working before I continue.
Thanks
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class ddSessionTool
{
public static void main (String[] args)
{
JFrame frame = new JFrame("Dungeons & Dragons Session Tool");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout (new BorderLayout());
panel.setBackground(Color.black);
panel.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8));
Gui gui = new Gui();
panel.add(gui);
frame.getContentPane().add(panel);
frame.pack();
frame.setSize(600,400);
frame.setLocation(100,100);
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Gui extends JPanel
{
public Gui()
{
JPanel guiWrapper = new JPanel();
guiWrapper.setLayout (new BorderLayout());
guiWrapper.setBackground(Color.red);
JPanel panelNorth = new JPanel();
JPanel panelSouth = new JPanel();
JPanel topLeft = new JPanel();
JPanel topLeftNorth = new JPanel();
JPanel topLeftCenter = new JPanel();
JPanel topLeftSouth = new JPanel();
JPanel topRight = new JPanel();
JPanel topRightNorth = new JPanel();
JPanel topRightCenter = new JPanel();
JPanel topRightSouth = new JPanel();
JPanel rollerSection = new JPanel();
JPanel rollDice = new JPanel();
JPanel battleOutput = new JPanel();
JButton add1 = new JButton("add");
JButton add2 = new JButton("add");
JButton remove1 = new JButton("remove");
JButton remove2 = new JButton("remove");
JButton d4 = new JButton("D4");
JButton d6 = new JButton("D6");
JButton d8 = new JButton("D8");
JButton d10 = new JButton("D10");
JButton d12 = new JButton("D12");
JButton d20 = new JButton("D20");
JButton d100 = new JButton("D100");
JLabel placeHolder = new JLabel("THIS TEST IS A PLACE HOLDER FOR SOMETHING ELSE!!!");
JLabel tlTitle = new JLabel("Enemies");
tlTitle.setForeground(Color.white);
JLabel trTitle = new JLabel("Players");
trTitle.setForeground(Color.white);
JLabel blTitle = new JLabel("Battle Area");
blTitle.setForeground(Color.white);
JLabel blBattleOutput = new JLabel("Battle Output");
blBattleOutput.setForeground(Color.white);
panelNorth.setLayout (new BorderLayout());
panelNorth.setBackground(Color.black);
panelSouth.setLayout (new BorderLayout());
panelSouth.setBackground(Color.black);
topLeft.setLayout (new BorderLayout());
topLeft.setBorder (BorderFactory.createEmptyBorder (0, 0, 4, 4));
topLeftNorth.setLayout(new FlowLayout());
topLeftNorth.setBackground(Color.blue);
topLeftCenter.setLayout(new FlowLayout());
topLeftCenter.setBackground(Color.gray);
topLeftSouth.setLayout(new FlowLayout());
topLeftSouth.setBackground(Color.gray);
topRight.setLayout (new BorderLayout());
topRight.setBorder (BorderFactory.createEmptyBorder (0, 0, 4, 0));
topRightNorth.setLayout(new FlowLayout());
topRightNorth.setBackground(Color.blue);
topRightCenter.setLayout(new FlowLayout());
topRightCenter.setBackground(Color.gray);
topRightSouth.setLayout(new FlowLayout());
topRightSouth.setBackground(Color.gray);
rollerSection.setLayout(new FlowLayout());
rollerSection.setBackground(Color.blue);
rollDice.setLayout(new BoxLayout(rollDice, BoxLayout.Y_AXIS));
rollDice.setBackground(Color.gray);
battleOutput.setLayout(new BoxLayout(battleOutput, BoxLayout.Y_AXIS));
battleOutput.setBackground(Color.gray);
topLeftNorth.add(tlTitle);
topLeftCenter.add(placeHolder);
topLeftSouth.add(add1);
topLeftSouth.add(remove1);
topRightNorth.add(trTitle);
topRightCenter.add(placeHolder);
topRightSouth.add(add2);
topRightSouth.add(remove2);
rollerSection.add(blTitle);
rollDice.add(d4);
rollDice.add(d6);
rollDice.add(d8);
rollDice.add(d10);
rollDice.add(d12);
rollDice.add(d20);
rollDice.add(d100);
battleOutput.add(blBattleOutput);
topLeft.add(topLeftNorth, BorderLayout.NORTH);
topLeft.add(topLeftCenter, BorderLayout.CENTER);
topLeft.add(topLeftSouth, BorderLayout.SOUTH);
topRight.add(topRightNorth, BorderLayout.NORTH);
topRight.add(topRightCenter, BorderLayout.CENTER);
topRight.add(topRightSouth, BorderLayout.SOUTH);
panelNorth.add(topLeft, BorderLayout.WEST);
panelNorth.add(topRight, BorderLayout.EAST);
panelSouth.add(rollerSection, BorderLayout.NORTH);
panelSouth.add(rollDice, BorderLayout.WEST);
panelSouth.add(battleOutput, BorderLayout.CENTER);
guiWrapper.add(panelNorth, BorderLayout.NORTH);
guiWrapper.add(panelSouth, BorderLayout.SOUTH);
add(guiWrapper, BorderLayout.WEST);
}
}
|
|
|
|
|
First even if you specify the back color of the parent panel the children panel are already overwriting it for example change the topLeftCenter.setBackground(Color.gray); to any color to see what I mean
|
|
|
|
|
if it is overwriting it for the children then why does the layout work except for those 3 panels? I am not quite certain as to exactly what you are trying to explain to me. Can you please elaborate?
|
|
|
|
|
ok let me brake it down.
1. In the gui class constructor to change the big gray box add setBackground(Color.yellow);
2. For the three panels you need to add topLeft.setBackground(Color.red); and topRight.setBackground(Color.green);
see it now?
|
|
|
|
|
Ok I think I am starting to understand what you are trying to explain to me. Since guiWrapper is the outermost JPanel, I set its background by setBackground(Color.yellow); And borders on my topLeft and topRight JPanels do not actually bleed through to the Panel behind them; since I set no background initially, they were that weird beige color and I needed to define them with topLeft.setBackground(Color.red); and topRight.setBackground(Color.green); .
I added the lines of code and set the color to darkGray , and it worked just fine. I see where my thinking went wrong to. Thank you so much for the help!
|
|
|
|
|