Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- public class TextWriter extends JPanel{
- public int width;
- public int height;
- public String r1 = "";
- public String r2 = "";
- public String r3 = "";
- public TextWriter(int w,int h){
- width = w;
- height = h;
- JFrame myframe= new JFrame();
- myframe.getContentPane().add(this);
- myframe.setTitle("TextWriter");
- myframe.setSize(width,height);
- myframe.setVisible(true);
- myframe.setBackground(Color.WHITE);
- }
- public void paintComponent(Graphics g){
- g.drawString(r1,20,30);
- g.drawString(r2,20,80);
- g.drawString(r3,20,140);
- }
- public void print1(String s){
- r1 += s;
- this.repaint();
- }
- public void reset1(String s){
- r1 = s;
- this.repaint();
- }
- public void print2(String s){
- r2 += s;
- this.repaint();
- }
- public void reset2(String s){
- r2 = s;
- this.repaint();
- }
- public void print3(String s){
- r3 += s;
- this.repaint();
- }
- public void reset3(String s){
- r3 = s;
- this.repaint();
- }
- }
- import javax.swing.*;
- public class TestTextWriter
- { public static void main(String[] args)
- { TextWriter writer = new TextWriter(300, 200);
- String s = JOptionPane.showInputDialog("Please type some text:");
- writer.print1(s);
- s = JOptionPane.showInputDialog("Try it again:");
- writer.print1(s);
- s = JOptionPane.showInputDialog("Once more:");
- writer.print2(s);
- s = JOptionPane.showInputDialog("Last time:");
- writer.print3(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement