How to popluate vector

I have a vector (items) in the following applet that I got from an outside source and I am wondering how to code in the values for the vector that are going to be graphed in the chart. I don't know Java at all and all that I want to do is build this simple applet. Anyone able to help out?
import java.awt.*;
import java.util.*;
import java.applet.*;
public class Plot1 extends java.applet.Applet {
Label statLabel = new Label("Label");
String title = "Cores to Order Data";
int min = 0;
int max = 30;
Graph stats = new Graph(title, min, max);
public void init() {
BorderLayout border = new BorderLayout();
setLayout(border);
add("North", statLabel);
add("Center", stats);
class GraphItem {
String title;
int value;
Color color;
public GraphItem(String title, int value, Color color) {
this.title = title;
this.value = value;
this.color = color;
}// end contructor
} // end GraphItem
class Graph extends java.awt.Canvas {
//variables needed
public int top;
public int bottom;
public int left;
public int right;
int titleHeight;
int labelWidth;
FontMetrics fm;
int padding = 4;
String title;
int min;
int max;
Vector items;
public Graph(String title, int min, int max) {
this.title = title;
this.min = min;
this.max = max;
items = new Vector();
} // end contructor
public void reshape (int x, int y, int width, int height) {
super.reshape(x, y, width, height);
fm = getFontMetrics(getFont());
titleHeight = fm.getHeight();
labelWidth = Math.max(fm.stringWidth(new Integer(min).toString()), fm.stringWidth(new Integer(max).toString()) + 2);
top = padding + titleHeight;
bottom = size().height - padding;
left = padding + labelWidth;
right = size().width - padding;
} //end reshape
public void paint (Graphics g) {
//draw the title
fm = getFontMetrics(getFont());
g.drawString(title, (size().width - fm.stringWidth(title))/2, top);
//draw max and min values
g.drawString(new Integer(min).toString(), padding, bottom);
g.drawString(new Integer(max).toString(), padding, top + titleHeight);
//draw the vertical and horizontal lines
g.drawLine(left, top, left, bottom);
g.drawLine(left, bottom, right, bottom);
} // end paint
public Dimension preferredSize() {
return(new Dimension(1000, 1000));
//Facility for adding and removing the items to be graphed
public void addItem(String name, int value, Color col) {
items.addElement(new GraphItem(name, value, col));
}// end addItem
public void addItem(String name, int value) {
items.addElement(new GraphItem(name, value, Color.black));
}// end addItem
public void removeItem(String name) {
for (int i = 0; i < items.size(); i++) {
if (((GraphItem)items.elementAt(i)).title.equals(name))
items.removeElementAt(i);
}//end removeItem
} //end Graph
class BarChart extends Graph {
int position;
int increment;
public BarChart(String title, int min, int max) {
super(title, min, max);
} // end constructor
public void paint(Graphics g) {
super.paint(g);
increment = (right - left)/(items.size());
position = left;
Color temp = g.getColor();
for (int i = 0; i < items.size(); i++) {
GraphItem item = (GraphItem)items.elementAt(i);
int adjustedValue = bottom - (((item.value - min)*(bottom - top))
/(max - min));
g.drawString(item.title, position + (increment -
fm.stringWidth(item.title))/2, adjustedValue - 2);
g.setColor(item.color);
g.fillRect(position, adjustedValue, increment,
bottom - adjustedValue);
position+=increment;
g.setColor(temp);
} // end paint
} // end BarChart
          

Hi,
If you are asking about how to use the code to graph a vector you can just alter your init method:
  public void init()
    BorderLayout border = new BorderLayout();
    setLayout(border);
    add("North", statLabel);
    // Vector from outside source
    Vector v = new Vector();
    v.addElement( new Integer( 10 ) );
    v.addElement( new Integer( 25 ) );
    v.addElement( new Integer( 15 ) );
    v.addElement( new Integer( 20 ) );
    v.addElement( new Integer( 5 ) );
    // Outside source to stats object
    for( int k = 0; k < v.size(); ++k )
      stats.addItem( k+"", ((Integer)v.elementAt( k )).intValue() );
    add("Center", stats);
  }Regards,
Manfred.

Similar Messages

  • How to use Vector or other ArrayList etc to store my JTree??

    How to use Vector or other ArrayList etc to store my JTree??
    Dear friends,
    I have following I posted before, but not get satisfactory answer, so I modify and repost again here.
    I have following code can add classes and students in the JTree,
    in class Computer Science, it has student Bill Brien,
    in Math, no,
    Then I I add Student Nancy, Laura, Peter into Computer Science Class,
    add AAAA, BBB, CCC into Math class,
    I create a new class called Chemistry, then I add DDD int Chemistry;
    so this JTree is dynamically changed,
    [1]. How can I dynamically save my current JTree with all above tree structure and its nodes in a Vector or ArrayList(not sure which one is best)??
    see code below:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class ModelJTreeTest extends JFrame {
      private JTree tree;
      private DefaultTreeModel model;
      private DefaultMutableTreeNode rootNode;
      public ModelJTreeTest() {
        DefaultMutableTreeNode philosophersNode = getPhilosopherTree();
        model = new DefaultTreeModel(philosophersNode);
        tree = new JTree(model);
        JButton addButton = new JButton("Add Class/Students");
        addButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            addPhilosopher();
        JButton removeButton = new JButton("Remove Selected Class/Students");
        removeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            removeSelectedPhilosopher();
        JPanel inputPanel = new JPanel();
        inputPanel.add(addButton);
        inputPanel.add(removeButton);
        Container container = getContentPane();
        container.add(new JScrollPane(tree), BorderLayout.CENTER);
        container.add(inputPanel, BorderLayout.NORTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);
        setVisible(true);
      private void addPhilosopher() {
        DefaultMutableTreeNode parent = getSelectedNode();
        if (parent == null) {
          JOptionPane.showMessageDialog(ModelJTreeTest.this, "Select Class", "Error",
              JOptionPane.ERROR_MESSAGE);
          return;
        String name = JOptionPane.showInputDialog(ModelJTreeTest.this, "Add Class/Students:");
        model.insertNodeInto(new DefaultMutableTreeNode(name), parent, parent.getChildCount());
      private void removeSelectedPhilosopher() {
        DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null)
          model.removeNodeFromParent(selectedNode);
      private DefaultMutableTreeNode getSelectedNode() {
        return (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      private DefaultMutableTreeNode getPhilosopherTree() {
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Students");
        DefaultMutableTreeNode ancient = new DefaultMutableTreeNode("Computer Science");
        rootNode.add(ancient);
        ancient.add(new DefaultMutableTreeNode("Bill Brian"));
        DefaultMutableTreeNode math = new DefaultMutableTreeNode("Maths");
        rootNode.add(math);  
        DefaultMutableTreeNode physics = new DefaultMutableTreeNode("Physics");
        rootNode.add(physics);
        return rootNode;
      public static void main(String args[]) {
        new ModelJTreeTest();
    }the actual Tree dynamically created somehow looks like following:
                             |            1.Peter
                             |---CS---    2. Nancy
                             |            3. Laura
                             |            4.Brian
                             |
    Root(University): -------|---Math- 1.AAA
                             |            2.BBB
                             |            3.CCC
                             |
                             |
                             |---Chemistry- 1. DDDThanks a lot
    Good weekends

    you can't directly store a tree in a list.Ummm... Just to be contrary... Yes you CAN store a tree in a table.... In fact that's how the windows file system works.
    Having said that... you would be well advised to investigate tree data-structures before resorting to flattening a tree into a list.
    So... Do you have a specific requirement to produce a List? Your umming-and-erring about Vector vs ArrayList makes it sound like you're still at the stage of choosing a datastructure.
    Cheers. Keith.

  • How to create Vector with reference to Collection

    hello experts,
    can someone let me know how to create vector with reference to Collection interface.
    Collection is an interface. and we cant create an instance of it. i'm not clear of what to pass in that constructor.
    Vector v = new Vector (Collection c);
    what are the possible objects of 'c'
    post some example code please.
    thanks

    Ever heard of reading the javadocs?
    "Collection is an interface. and we cant create an instance of it." - you don't understand interfaces, then.
    // I certainly can create a Collection - here's one
    Collection c = new ArrayList();
    // Now I'll add some Strings to my Collection.
    c.add("foo");
    c.add("bar");
    c.add("baz");
    // Now I'll make a Vector out of it.
    Vector v = new Vector(c);%

  • How to create vector portrait like the images as attached

    i want to create these kind of portrait. How will I do ...

    Pen tool to create the vector shapes and gradient mesh tool to make smooth transitions for the highlights and shadows. Illustrator doesn't have a function or tool that creates images like these.. Only the basic tools to create images like these. This question is kind of like what is the method to create an oil painting on canvas. you use a brush and paint to create the desired image..l
    I Know that's not helpful but it's the answer.. Here's a decent start  regarding how to begin vectorizing an image in this fashion..
    http://m.youtube.com/watch?v=aiPAG5eCG20

  • How to send Vector to Servlet?

    hi~~
    i want know that method of communicate form applet to Servlet.
    So far as I am concerned, Applet can't use I/O because of security.. but it can communicate with Servlet of calling the Applet.
    then, for example Vector.... How can send Vector to Servlet..

    The same way you send anything to a servlet, and the same way you send a vector to anywhere! You can do it a few ways, here's the one you'll see most of the time:
    URL servletURL = new URL(getDocumentBase(), "/servlet/myServlet");
    // Hope it's HTTP.  You probably should use instanceof before casting here.
    HttpURLConnection conn = (HttpURLConnection)servletURL.openConnection();
    conn.setDoOutput(true);
    ObjectOutputStream out = new ObjectOutputStream(conn.getOutputStream());
    out.writeObject(myVector);

  • How to cast vector to vector with out using loop. and how to override "operator =" of vector for this kind of condition.

    Hi All How to TypeCast in vector<>...  typedef  struct ...  to class... 
    //how to cast the vector to vector cast with out using loop
    // is there any way?
    //================ This is Type Definition for the class of ClsMytype=====================
    typedef struct tagClsMytype
    CString m_Name;
    int m_Index;
    double m_Value;
    } xClsMytype;
    //================ End of Type Definition for the class of ClsMytype=====================
    class ClsMytype : public CObject
    public:
    ClsMytype(); // Constructor
    virtual ~ClsMytype(); // Distructor
    ClsMytype(const ClsMytype &e);//Copy Constructor
    // =========================================
    DECLARE_SERIAL(ClsMytype)
    virtual void Serialize(CArchive& ar); /// Serialize
    ClsMytype& operator=( const ClsMytype &e); //= operator for class
    xClsMytype GetType(); // return the typedef struct of an object
    ClsMytype& operator=( const xClsMytype &e);// = operator to use typedef struct
    ClsMytype* operator->() { return this;};
    operator ClsMytype*() { return this; };
    //public veriable decleare
    public:
    CString m_Name;
    int m_Index;
    double m_Value;
    typedef struct tagClsMyTypeCollection
    vector <xClsMytype> m_t_Col;
    } xClsMyTypeCollection;
    class ClsMyTypeCollection : public CObject
    public:
    ClsMyTypeCollection(); // Constructor
    virtual ~ClsMyTypeCollection(); // Distructor
    ClsMyTypeCollection(const ClsMyTypeCollection &e);//Copy Constructor
    DECLARE_SERIAL(ClsMyTypeCollection)
    virtual void Serialize(CArchive& ar);
    xClsMyTypeCollection GetType();
    ClsMyTypeCollection& operator=( const xClsMyTypeCollection &e);
    ClsMyTypeCollection& operator=( const ClsMyTypeCollection &e); //= operator for class
    void Init(); // init all object
    CString ToString(); // to convert value to string for the display or message proposed
    ClsMyTypeCollection* operator->() { return this;}; // operator pointer to ->
    operator ClsMyTypeCollection*() {return this;};
    public:
    vector <ClsMytype> m_t_Col;
    //private veriable decleare
    private:
    //===================================================
    ClsMytype& ClsMytype::operator=( const xClsMytype &e )
    this->m_Name= e.m_Name;
    this->m_Index= e.m_Index;
    this->m_Value= e.m_Value;
    return (*this);
    //==========================Problem for the vector to vector cast
    ClsMyTypeCollection& ClsMyTypeCollection::operator=( const xClsMyTypeCollection &e )
    this->m_t_Col= (vector<ClsMytype>)e.m_t_Col; // how to cast
    return (*this);
    Thanks in Advance

    Hi Smirt
    You could do:
    ClsMyTypeCollection* operator->() {
    returnthis;};
    // operator pointer to ->
    operatorClsMyTypeCollection*()
    {returnthis;};
    public:
    vector<ClsMytype>
    m_t_Col;//??
    The last line with "vector<xClsMytype>
    m_t_Col;". It compiles but I doubt that is what you want.
    Regards
    Chong

  • How to reveal vectors in PDF file.

    I've got a PDF file composed entirely of vector paths. Since the image was too large for the screen the document was saved as an 8.5x11" file, even though the remaining parts of the image are there. However, I can't seem to reveal them by deleting the clipping mask, even though another person can, using Illustrator CS2.
    As you can see in this Flash video: http://www.screentoaster.com/watch/stVUNSQEFIR1xXSVRZWFpfUVJT/cs, it takes them all of about 10 seconds to do, but when I try this, I don't get that result.
    Can someone describe in detailed, step-by-step instructions how to accomplish this same result? I need to know everything you do, including the tool and/or menu command you use for each step, and what should happen with each one.

    Yes, I tried deleting the Clipping Path, but I still see only the parts that are shown in the previous ScreenShot 1.png file. So, I decided to take out my copy of Illustrator CS3 that I had never installed before and it works perfectly there, which seems very strange. It makes no sense that this wouldn't work in Illustrator CS2 on the Mac, but works fine on Windows. Equally stupid is that it works fine in CS3 on the Mac.
    I sense this is an undocumented (or unadmitted) bug, courtesy of Adobe and their sloppy programmers.

  • How to use vector file without adobe illustrator?? please help

    I am using the free trial period of adobe illustrator to creat a logo.  I don't want to buy illustrator b/c I don't plan on using the program for anything else,  I would like to save my logo in some kind of vector format so I can use it for lots of different printing options.  But I can't figure out how to do this b.c my computer won't open the file without illustrator.  Is there anyway to creat a usable print friendly logo without buying illustrator? Thanks for any help!

    I believe if you export it to wmf or emf you will have a Vector file that can be used in word or powerpoint and can be placed in other programs as can ai files which can be placed in word or powerpoint documents as vector files.
    Flash (swf) is another way of saving it and it is also vector.
    However even though you say you will never have use for Illustrator which is what I thought in 1995 when I use it to create a logo, I soon found more use for it and every year since have found a project that has rewarded me many times the cost of the application once I had purchased it. Most of which I never thought I had the need for and probably would not have even made the attempt to make the effort and the profit if I did not own the license.
    And every time I say to myself what do i have this application for the opportunities arises yet again.
    I thought I would share my experience with you.

  • How to use vector in JTable? Please help......

    Hi there
    I can use JTable using object array to manupulate data but it has a limitation of defining number of rows of the array. Alternatively i want to use vector. Anyone help me how to convert to using vector.
    Regards.
    mortoza, Dhaka

    hi,
    you could either use javax.swing.table.DefaultTableModel because this class uses a java.util.Vector for data storage or you could implements your own TableModel by extending javax.swing.table.AbstractTableModel.
    best regards, Michael

  • How export my vector flash to illustrator?

    Hi,
    In all software adobe CC the .fxg extenxtion has remove (she is abandoned),
    Now how can I export my vector illustrations to Illustrator?

    Hi All,
    Flash Pro CC 2014 (v14.0.0.110) is now available for download via the Creative Cloud App and Adobe website.
    We have added SVG Export feature to Flash Pro with this new release. You will now be able to export out vector content from the selected frame as an SVG image that can be opened directly in a Browser and even imported in Adobe Illustrator.
    SVG Export option will be available via the Publish Settings as well as via File Menu > Export > Export Image option.
    Along with this, we have added several new features with this release. Complete list is available at these links:
    Overview:         https://www.adobe.com/in/products/flash.html
    Whats new:      https://helpx.adobe.com/flash/using/whats-new.html
    Release Notes: https://helpx.adobe.com/flash/release-note/flash-professional-cc-2014.html
    Thanks,
    Nipun

  • How to Call vector in Jsp from My factory class

    Hi all,
    I am new to singleton,I written a singleton class,One more all so name is getAllFactory(),this method returns vector which i am going to adding my data to xxDto finally i am adding this xxDto to my Vector in the singleton class.
    I need help how to call that vector in my jsp page...can any body plzz suggest to me.
    Thanks
    dilse

    import your singleton class to your JSP using page directive.
    And also import Vector class.
    Then as usual create object to vector class
    Vector v = singletonClassObject.getAllFactory()
    thats enough.

  • How to draw vector shape?

    I use following statement to draw a shape
    [CODE]for(....){
      sprite.graphics.beginFill(..);
      sprite.graphics.drawRect(x,y,1,1);
      sprite.graphics.endFill();
    }[/CODE]
    But I find above shape is not vector shape.Because I change the IE size,I find the size of shape don't automatic change. How to use sprite.graphics to create vector shape?
    Thanks

    Set Flash object size to 100% x 100% in the HTML - then you'll see your drawing changes the size as you resize the browser window.
    Kenneth Kawamoto
    http://www.materiaprima.co.uk/

  • How to save vector work sharp for web?

    Hello guys, I need all your help!
    I am trying to import a full color vector work from illustrator into an iPad.
    The original illustrator file is about 10MB and I am trying to achive size that is under 128K.
    I used "save for web" but result is not sharp enough at all.
    Is there a better way to save without loosing much detail and still keep the size small from illustrator?
    Should I import to photoshop first to save?  I am just throwing ideas.
    Thanks,
    W.

    I have finally figure out how to save files in smaller size with out loose much quality but now I am encounter with the another issue.
    Files' (JPEG) typefaces are sharp and legible look perfect on iPad, when the same file (JPEG) imported to iPhone, the typeface was not able to read.
    iPad is much bigger than iPhone.  Images work perfect for iPad in theory it shouldn't have lack pixel issue.
    It really beats me.  I don't know how to figure this out.  If you have any idea, please let me know your insight.
    Thanks,
    W.

  • How to create vector growth animations

    Hi,
    How do I create those animated vector graphics effects make popular in MTV promos, in which a graphic simulates growth with patterns reveals itself in different stages. Something similar to animated hand writing.
    I know it has something to do with animated mask, but I have tried, it is quite difficult to manage the mask to reveal different portion as intended.
    Is there an easier way that I do not know of?
    An example of the animation can be found at
    http://www.digitaljuice.com/products/products.asp?pid=329&tab=t3#tabs
    Please advise
    Thanks
    Ken

    Hi Adam,
    Thanks for the info, and yes your project is exactly what I am looking for, however, I am still on Motion 2, your project is done on Motion 3.
    I think this effect can be done on motion 2 or do I need motion 3 to execute this effect? Is it possible to export a version to motion 2?
    Neverthelss thanks for your help, will try to search fo more help in the forum regarding this.
    regards
    Ken

  • How to use Vectors ?????????

    Hi guys, i am a newbie in java and about to die due to some stressful assignments. I am not asking u to help in assignment. Just please share some knowledges about vector. How to use it? so that i can use it in my assignment. Thank u .
    AND IN THIS CODE BELOW: WHY DO WE HAVE TO IMPORT MARK;
    THERE IS ANOTHER CLASS CALLED MARK DEFINED ELSEWHERE.
    import java.util.Vector;
    import Mark;
    public class Student {
    private String name;
    private Vector subjectResults; // the implementation of the relationship from Student - Mark
    public Student (String name) {
    this.name = name;
    subjectResults = new Vector ();
    public void insertMark (int value) {
    this.subjectResults.addElement (new Mark (value)); // WHAT DOES THIS LINE MEAN ?
    public int findHighestMark () {
    int size = subjectResults.size (); //cache the result
    int highestMark = 0;
    for (int i = 0; i < size; i++) {
    Mark result = (Mark) subjectResults.get (i); //WHY DO WE HAVE TO PUT "(MARK)" ?
    if (result.get () > highestMark) {
    highestMark = result.get ();
    return highestMark;

    I'm going to guess that Mark is a class provided to you. Do you have the Mark.java file? Or only Mark.class? If you have Mark.java, see if the first line is package Mark;
    It shouldn't be.
    You shouldn't need to import Mark.
    A vector is a like a dynamic array (not really, but in simple terms it is), you can keep adding things to it. You can insert stuff in the middle, you can extract stuff from the middle (doesn't leave a gap).
    You use it with:
    public void addElement(Object toAdd)
    public Object elementAt(int index)
    These are the two most important methods of Vector.
    Note that it returns an Object. You won't be able to do anything useful with an Object (except for toString()), so you'll need to cast it to whatever you're expecting (Student or Mark or something).
    That's the basics of Vectors, hope this helps,
    Radish21

Maybe you are looking for

  • How to use Iden SDK with WTK 2.5.1 ?

    I have installed WTK, and it has been working but I realized I forgot to add the iden SDK for my motorola phone. I installed the SDK but I assume I need to link the files to WTK somehow? What I am wanting to do : So... I think I know what I need... I

  • Problem in compiling jsp file

    Hi, i am using tomcat 4.12 and jdk 1.4. My login page contains 3 frames. after succesful login into ur application, 7 frames are getting called. i have called a jsp page for each frame. sometimes while accessing my application, i am getting jasper ex

  • JSF 2.0 beta2 - JavaScript not execute in ajaxreponse +  Parameters: Invali

    Hi, I'm testing JSF2.0 beta2. I found the following problems: 1) The JavaScript is not executed in the ajaxresponse. I solved it by adding the following JavaScript code to my xhtml file:           function executeScripts(data) {               if (dat

  • File open  event  지속에 대해..

    SELECT * FROM V$SQLAREA; SELECT * FROM V$ACCESS; 를 하면 v$session_wait에 "file open" event 와 cpu 사용은 증가되며 조회는 안되고 종료할 수 밖에 없습니다... (V$ACCESS 는 계속 기다려 보니 200개 정도 였습니다..) 무엇이 문제인가요...

  • How to include microsoft.research.kinect.dll file?

    When trying to activate a demo VI file using xbox kinect, MS-SDK and LabView 2011 we get the announcement that the file "microsoft.research.kinect.dll" is not found. Even after we put it in the relevant directory we got the same message. Does any one