SlideShare a Scribd company logo
ViewerFrame.java
import javax.swing.JFrame;
public class ViewerFrame extends JFrame
{
public ViewerFrame(){
OpsPanel OP = new OpsPanel();
add(OP);
}
public static void main(String[] args){
ViewerFrame v = new ViewerFrame();
v.setSize(1000,600);
v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v.setVisible(true);
}
}
OpsPanel.java
import java.awt.Graphics;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JPanel;
import java.awt.Font;
public class OpsPanel extends JPanel{
private int x = 50;
private int y = 50;
private int titleX = 50;
private int titleY = 30;
private Scanner in;
private String intLine1;
private String intLine2;
private String sign;
private ArrayList list = new ArrayList<>();
public OpsPanel(){
//Open file for reading and catch if file isn't there.
try{
in = new Scanner(new FileReader("addsAndSubtracts.txt"));
}
catch(FileNotFoundException nf){
System.out.println("File Not Found!");
}
while(in.hasNext()){
intLine1 = in.next();
sign = in.next();
intLine2 = in.next();
System.out.println(intLine1 + sign + intLine2);
list.add(new Ops(intLine1, intLine2, sign));
}
repaint();
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 20));
g.drawString("Operand 1 +/- Operand 2 = Result", titleX, titleY);
g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 12));
for (Ops o: list) {
o.drawInfo(g, x, y);
y+=15;
}
}
}
Ops.java
import java.util.LinkedList;
import java.awt.*;
import javax.swing.*;
//import java.util.Formatter;
public class Ops extends JPanel{
private String bigInt1;
private String sign1;
private String bigInt2;
private String sign2;
private String opSign;
private String calcSign;
private LinkedList largeInt;
private LinkedList smallInt;
private LinkedList resultInt;
public Ops(String bI1, String bI2, String sign){
//Save original sign for display.
opSign = sign;
//Save signs on strings.
if(bI1.charAt(0) == '-'){
bI1 = bI1.substring(1);
sign1 = "-";
}
else{
sign1 = "";
}
if(bI2.charAt(0) == '-'){
bI2 = bI2.substring(1);
sign2 = "-";
}
else{
sign2 = "";
}
//Test lengths for padding and other operations.
if(bI1.length() > bI2.length()){
}
else if(bI2.length() > bI1.length()){
}
else{
}
if(sign.equalsIgnoreCase("+")){
if(sign1.equalsIgnoreCase("") && sign2.equalsIgnoreCase("")){
}
else{
}
}
}
public void calcResult(String bI1, String bI2, String calcS){
}
@Override
public String toString(){
String.format("");
return sign1 + bigInt1 + " " + opSign + " " + sign2 + bigInt2 + " = " + resultInt;
}
public void drawInfo(Graphics g, int x, int y){
g.drawString(toString(), x,y);
}
}
Solution
ViewerFrame.java
import javax.swing.JFrame;
public class ViewerFrame extends JFrame
{
public ViewerFrame(){
OpsPanel OP = new OpsPanel();
add(OP);
}
public static void main(String[] args){
ViewerFrame v = new ViewerFrame();
v.setSize(1000,600);
v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v.setVisible(true);
}
}
OpsPanel.java
import java.awt.Graphics;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JPanel;
import java.awt.Font;
public class OpsPanel extends JPanel{
private int x = 50;
private int y = 50;
private int titleX = 50;
private int titleY = 30;
private Scanner in;
private String intLine1;
private String intLine2;
private String sign;
private ArrayList list = new ArrayList<>();
public OpsPanel(){
//Open file for reading and catch if file isn't there.
try{
in = new Scanner(new FileReader("addsAndSubtracts.txt"));
}
catch(FileNotFoundException nf){
System.out.println("File Not Found!");
}
while(in.hasNext()){
intLine1 = in.next();
sign = in.next();
intLine2 = in.next();
System.out.println(intLine1 + sign + intLine2);
list.add(new Ops(intLine1, intLine2, sign));
}
repaint();
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 20));
g.drawString("Operand 1 +/- Operand 2 = Result", titleX, titleY);
g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 12));
for (Ops o: list) {
o.drawInfo(g, x, y);
y+=15;
}
}
}
Ops.java
import java.util.LinkedList;
import java.awt.*;
import javax.swing.*;
//import java.util.Formatter;
public class Ops extends JPanel{
private String bigInt1;
private String sign1;
private String bigInt2;
private String sign2;
private String opSign;
private String calcSign;
private LinkedList largeInt;
private LinkedList smallInt;
private LinkedList resultInt;
public Ops(String bI1, String bI2, String sign){
//Save original sign for display.
opSign = sign;
//Save signs on strings.
if(bI1.charAt(0) == '-'){
bI1 = bI1.substring(1);
sign1 = "-";
}
else{
sign1 = "";
}
if(bI2.charAt(0) == '-'){
bI2 = bI2.substring(1);
sign2 = "-";
}
else{
sign2 = "";
}
//Test lengths for padding and other operations.
if(bI1.length() > bI2.length()){
}
else if(bI2.length() > bI1.length()){
}
else{
}
if(sign.equalsIgnoreCase("+")){
if(sign1.equalsIgnoreCase("") && sign2.equalsIgnoreCase("")){
}
else{
}
}
}
public void calcResult(String bI1, String bI2, String calcS){
}
@Override
public String toString(){
String.format("");
return sign1 + bigInt1 + " " + opSign + " " + sign2 + bigInt2 + " = " + resultInt;
}
public void drawInfo(Graphics g, int x, int y){
g.drawString(toString(), x,y);
}
}

More Related Content

PDF
This is Due to highest Cncentration of Comon Ions.pdf
PDF
There is no reaction. The nearest I can think of .pdf
PDF
The decomposition of hydrogen peroxide to gaseous.pdf
PDF
NaBr Na is metal and Br is electronegative. All.pdf
PDF
it is not hydrolyzed because of steric hindrance .pdf
PDF
Im not entirely sure what this is asking. I ass.pdf
PDF
HI = hydrogen iodide .pdf
PDF
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
This is Due to highest Cncentration of Comon Ions.pdf
There is no reaction. The nearest I can think of .pdf
The decomposition of hydrogen peroxide to gaseous.pdf
NaBr Na is metal and Br is electronegative. All.pdf
it is not hydrolyzed because of steric hindrance .pdf
Im not entirely sure what this is asking. I ass.pdf
HI = hydrogen iodide .pdf
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf

More from annaindustries (20)

PDF
First remember that non polar compounds are solub.pdf
PDF
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
PDF
The standard form of a complex number is a real number plusminus an.pdf
PDF
DNA and RNA .pdf
PDF
Solution-1. For this weSolutionSolution-1. For this we.pdf
PDF
Question) one or more attributes that comprise a primary key in a ro.pdf
PDF
pls provide the dataSolutionpls provide the data.pdf
PDF
Photosynthesis - is the unique process that is limited to plant king.pdf
PDF
Please follow the code and comments for description a)CODE #.pdf
PDF
Optimized Waterfall processIs a common project methodology and it.pdf
PDF
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
PDF
It is the main program that implement the min(), max(), floor(), cei.pdf
PDF
An overlay network may be a electronic network thats designed on h.pdf
PDF
Alkylating agents, or their reactive intermediates, form covalent bo.pdf
PDF
Hi,I have updated the code as per your requirement. Highlighted th.pdf
PDF
dil. HCl than after it get hydrolysed completely the pH of the solut.pdf
PDF
I have selected Alibaba stock for analysis.As per the data given i.pdf
PDF
fr = esfs = resSolutionfr = esfs = res.pdf
PDF
FalseHuman cells do not have separate genes for each antibody Mole.pdf
PDF
Cybercrime simply means crime that happens in cyberspace ie the wor.pdf
First remember that non polar compounds are solub.pdf
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
The standard form of a complex number is a real number plusminus an.pdf
DNA and RNA .pdf
Solution-1. For this weSolutionSolution-1. For this we.pdf
Question) one or more attributes that comprise a primary key in a ro.pdf
pls provide the dataSolutionpls provide the data.pdf
Photosynthesis - is the unique process that is limited to plant king.pdf
Please follow the code and comments for description a)CODE #.pdf
Optimized Waterfall processIs a common project methodology and it.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
It is the main program that implement the min(), max(), floor(), cei.pdf
An overlay network may be a electronic network thats designed on h.pdf
Alkylating agents, or their reactive intermediates, form covalent bo.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
dil. HCl than after it get hydrolysed completely the pH of the solut.pdf
I have selected Alibaba stock for analysis.As per the data given i.pdf
fr = esfs = resSolutionfr = esfs = res.pdf
FalseHuman cells do not have separate genes for each antibody Mole.pdf
Cybercrime simply means crime that happens in cyberspace ie the wor.pdf
Ad

Recently uploaded (20)

PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
1_English_Language_Set_2.pdf probationary
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
advance database management system book.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Weekly quiz Compilation Jan -July 25.pdf
Computing-Curriculum for Schools in Ghana
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A systematic review of self-coping strategies used by university students to ...
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Final Presentation General Medicine 03-08-2024.pptx
IGGE1 Understanding the Self1234567891011
Paper A Mock Exam 9_ Attempt review.pdf.
UNIT III MENTAL HEALTH NURSING ASSESSMENT
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Digestion and Absorption of Carbohydrates, Proteina and Fats
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Final Presentation General Medicine 03-08-2024.pptx
1_English_Language_Set_2.pdf probationary
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
advance database management system book.pdf
Ad

ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf

  • 1. ViewerFrame.java import javax.swing.JFrame; public class ViewerFrame extends JFrame { public ViewerFrame(){ OpsPanel OP = new OpsPanel(); add(OP); } public static void main(String[] args){ ViewerFrame v = new ViewerFrame(); v.setSize(1000,600); v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); v.setVisible(true); } } OpsPanel.java import java.awt.Graphics; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JPanel; import java.awt.Font; public class OpsPanel extends JPanel{ private int x = 50; private int y = 50; private int titleX = 50; private int titleY = 30; private Scanner in; private String intLine1;
  • 2. private String intLine2; private String sign; private ArrayList list = new ArrayList<>(); public OpsPanel(){ //Open file for reading and catch if file isn't there. try{ in = new Scanner(new FileReader("addsAndSubtracts.txt")); } catch(FileNotFoundException nf){ System.out.println("File Not Found!"); } while(in.hasNext()){ intLine1 = in.next(); sign = in.next(); intLine2 = in.next(); System.out.println(intLine1 + sign + intLine2); list.add(new Ops(intLine1, intLine2, sign)); } repaint(); } @Override public void paintComponent(Graphics g){
  • 3. super.paintComponent(g); g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 20)); g.drawString("Operand 1 +/- Operand 2 = Result", titleX, titleY); g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 12)); for (Ops o: list) { o.drawInfo(g, x, y); y+=15; } } } Ops.java import java.util.LinkedList; import java.awt.*; import javax.swing.*; //import java.util.Formatter; public class Ops extends JPanel{ private String bigInt1; private String sign1; private String bigInt2; private String sign2; private String opSign; private String calcSign; private LinkedList largeInt; private LinkedList smallInt; private LinkedList resultInt; public Ops(String bI1, String bI2, String sign){ //Save original sign for display.
  • 4. opSign = sign; //Save signs on strings. if(bI1.charAt(0) == '-'){ bI1 = bI1.substring(1); sign1 = "-"; } else{ sign1 = ""; } if(bI2.charAt(0) == '-'){ bI2 = bI2.substring(1); sign2 = "-"; } else{ sign2 = ""; } //Test lengths for padding and other operations. if(bI1.length() > bI2.length()){ } else if(bI2.length() > bI1.length()){ } else{ } if(sign.equalsIgnoreCase("+")){ if(sign1.equalsIgnoreCase("") && sign2.equalsIgnoreCase("")){ } else{
  • 5. } } } public void calcResult(String bI1, String bI2, String calcS){ } @Override public String toString(){ String.format(""); return sign1 + bigInt1 + " " + opSign + " " + sign2 + bigInt2 + " = " + resultInt; } public void drawInfo(Graphics g, int x, int y){ g.drawString(toString(), x,y); } } Solution ViewerFrame.java import javax.swing.JFrame; public class ViewerFrame extends JFrame { public ViewerFrame(){ OpsPanel OP = new OpsPanel(); add(OP);
  • 6. } public static void main(String[] args){ ViewerFrame v = new ViewerFrame(); v.setSize(1000,600); v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); v.setVisible(true); } } OpsPanel.java import java.awt.Graphics; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JPanel; import java.awt.Font; public class OpsPanel extends JPanel{ private int x = 50; private int y = 50; private int titleX = 50; private int titleY = 30; private Scanner in; private String intLine1; private String intLine2; private String sign; private ArrayList list = new ArrayList<>(); public OpsPanel(){ //Open file for reading and catch if file isn't there. try{
  • 7. in = new Scanner(new FileReader("addsAndSubtracts.txt")); } catch(FileNotFoundException nf){ System.out.println("File Not Found!"); } while(in.hasNext()){ intLine1 = in.next(); sign = in.next(); intLine2 = in.next(); System.out.println(intLine1 + sign + intLine2); list.add(new Ops(intLine1, intLine2, sign)); } repaint(); } @Override public void paintComponent(Graphics g){ super.paintComponent(g); g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 20)); g.drawString("Operand 1 +/- Operand 2 = Result", titleX, titleY); g.setFont(new Font(g.getFont().getFontName(),Font.PLAIN, 12)); for (Ops o: list) { o.drawInfo(g, x, y); y+=15;
  • 8. } } } Ops.java import java.util.LinkedList; import java.awt.*; import javax.swing.*; //import java.util.Formatter; public class Ops extends JPanel{ private String bigInt1; private String sign1; private String bigInt2; private String sign2; private String opSign; private String calcSign; private LinkedList largeInt; private LinkedList smallInt; private LinkedList resultInt; public Ops(String bI1, String bI2, String sign){ //Save original sign for display. opSign = sign; //Save signs on strings. if(bI1.charAt(0) == '-'){ bI1 = bI1.substring(1); sign1 = "-"; } else{ sign1 = "";
  • 9. } if(bI2.charAt(0) == '-'){ bI2 = bI2.substring(1); sign2 = "-"; } else{ sign2 = ""; } //Test lengths for padding and other operations. if(bI1.length() > bI2.length()){ } else if(bI2.length() > bI1.length()){ } else{ } if(sign.equalsIgnoreCase("+")){ if(sign1.equalsIgnoreCase("") && sign2.equalsIgnoreCase("")){ } else{ } } } public void calcResult(String bI1, String bI2, String calcS){ }
  • 10. @Override public String toString(){ String.format(""); return sign1 + bigInt1 + " " + opSign + " " + sign2 + bigInt2 + " = " + resultInt; } public void drawInfo(Graphics g, int x, int y){ g.drawString(toString(), x,y); } }