Right now, all it does is open a window, and does not display any text.
No, this is not for school work, so you are not helping anybody cheat.
import java.awt.Container;
import javax.swing.JFrame;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.lang.InterruptedException;
public class DebateLine extends JFrame implements MouseListener
{
private DPanel canvas;
public DebateLine()
{
super("Debate Software- Proof of Concept");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,600);
setExtendedState(this.getExtendedState()|JFrame.MAXIMIZED_BOTH);//I just copied this code off the net, it maximizes the window
Container con = this.getContentPane();
canvas = new DPanel();
con.add(canvas);
setVisible(true);
}
private boolean clicked=false;
public void readLines()
{
canvas.repaint();
while(!canvas.getWhetherDone())
{
while(!clicked)
{
try{
Thread.sleep(10);
}catch(InterruptedException e)
{return;}
}
canvas.repaint();
canvas.show();
}
}
public static void main(String arg[])
{
DebateLine deb=new DebateLine();
deb.readLines();
}
public void mouseClicked(MouseEvent e)
{
clicked=true;
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.JPanel;
import java.io.IOException;
public class DPanel extends JPanel
{
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.JPanel;
import java.io.IOException;
public class DPanel extends JPanel
{
private String letters;
private String[] feed;
private int distanceInList;
private boolean done=false;
public boolean getWhetherDone(){return done;}
public DPanel()
{
FileChararray generator = new FileChararray();
distanceInList=0;
try
{
feed=generator.entireText();
}
catch(IOException e)
{
return;
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d=(Graphics2D)g;
g2d.setFont(new Font("serif",Font.BOLD,80));
FontMetrics fm=g2d.getFontMetrics();
int down=20;
for(int spot=distanceInList;spot<feed.length;)
{
if(fm.stringWidth(letters+feed[spot])<getWidth())//as long as there is enough space for words, more words will be added
{
letters+=feed[spot]+" ";
distanceInList++;
}
else if(getHeight()<down+fm.getHeight())// when the line is full of words,the line is displayed.
{
g2d.drawString(letters,0,down);
down=down+fm.getHeight();
letters=feed[spot];
distanceInList++;
}
else
{
letters=feed[spot];//when there is no more space for more lines of text
down=20;
distanceInList++;
return;
}
}
done=true;
}
}
This post has been edited by GreenCamper: 03 May 2008 - 02:59 PM

New Topic/Question
Reply




MultiQuote






|