id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
e90221a2-2bf7-427d-a7ca-5c2052f487c8 | @Override
public String toString(){
return "Naam:"+naam+
" Brouwer:"+brouwer.getNaam()+
" Soort:"+soort.getNaam()+
" Alcoholpercentage:"+alcohol+
" Prijs:"+prijs;
} |
47289311-c25f-4c50-ba84-cf6b1af5106d | protected Bestelbon(){
} |
939202d8-1508-4962-aefc-edb1d12dcd32 | public Bestelbon(String naam, Adres adres, Set<BestelbonLijn> bestelbonLijnen){
this.naam=naam;
this.adres=adres;
this.bestelbonLijnen=bestelbonLijnen;
} |
3b7e5ef0-c819-4660-9911-d3aa99daf409 | public Bestelbon(Set<BestelbonLijn> bestelbonLijnen){
this.bestelbonLijnen=bestelbonLijnen;
} |
be6c0644-a664-48ca-a80e-58d793c20252 | public long getBonNr() {
return bonNr;
} |
5be0f72f-7207-444c-b9af-f5c3ad6cb478 | public Set<BestelbonLijn> getBestelbonLijnen() {
return Collections.unmodifiableSet(bestelbonLijnen);
} |
20eb873e-5386-4fae-84e2-c5cb729ac67d | public BigDecimal getTotaal() {
BigDecimal totaal = BigDecimal.ZERO;
for (BestelbonLijn bestelbonLijn : bestelbonLijnen) {
totaal= totaal.add(bestelbonLijn.getTotaal());
}
return totaal;
} |
45907ac4-7aad-421f-bae3-aaa0a2baa859 | protected Brouwer(){
} |
32b28ef3-f27d-4d6e-b1b3-08af3719a85e | public long getBrouwerNr() {
return brouwerNr;
} |
0ec2767c-7fea-489d-87ca-485e29f22bc0 | public String getNaam() {
return naam;
} |
03cb3506-707b-41fe-865c-39c152352bfd | public Adres getAdres() {
return adres;
} |
b728fbac-fc86-4b66-a607-7b564a636387 | public Set<Bier> getBieren() {
return Collections.unmodifiableSet(bieren);
} |
03ac4d5c-1625-435c-9c0d-1b3ae541ae5f | protected Soort() {
} |
c932ec67-fb6c-434a-8795-ed2e112cf3a7 | public long getSoortNr() {
return soortNr;
} |
ea719ca8-c13b-4a40-9ec5-524a99a312f0 | public String getNaam() {
return naam;
} |
8054d8a3-5359-4b84-81fa-bdecf913a6ba | @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if(session!=null){
request.setAttribute("mandje", session.getAttribute("mandje"));
}
request.setAttribute("brouwers", brouwerService.findAll());
request.getRequestDispatcher(VIEW).forward(request, response);
} |
2ee13bc6-c04c-47a5-b0d2-17afc48dff1f | @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
HttpSession session = request.getSession(false);
if(session!=null){
request.setAttribute("mandje", session.getAttribute("mandje"));
}
long brouwerId = Long.parseLong(request.getParameter("brouwerId"));
if (brouwerId < 0) {
request.setAttribute("fout", "BrouwerId moet een positief getal zijn.");
} else {
request.setAttribute("brouwer", brouwerService.readBrouwerAndBier(brouwerId));
}
}
catch(NumberFormatException ex){
request.setAttribute("fout","BrouwerId mag niet leeg zijn. Mag enkel cijfers bevatten.");
}
catch (NoResultException ex) {
}
request.getRequestDispatcher(VIEW).forward(request, response);
} |
daf180b3-4dd4-4ff7-bde7-2fdd85e1e9a4 | @Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
HttpSession session = request.getSession(false);
Long bierId = Long.parseLong(request.getParameter("bierId"));
if (session != null) {
request.setAttribute("mandje", session.getAttribute("mandje"));
@SuppressWarnings("unchecked")
Map<Long, Integer> mandje = (Map<Long, Integer>) session
.getAttribute("mandje");
if (mandje.containsKey(bierId)) {
request.setAttribute("bierAlInMandje",
"Bier is al in mandje. Nieuwe waarde overschrijft oude.");
request.setAttribute("oudAantal", mandje.get(bierId));
}
}
if (bierId < 0){
request.setAttribute("fout", "bierNr moet een positief getal zijn.");
} else {
request.setAttribute("bier",
bierService.readBierSoortAndBrouwer(bierId));
}
} catch (NumberFormatException ex) {
request.setAttribute("fout",
"BierNr mag niet leeg zijn. Mag enkel cijfers bevatten.");
} catch (NoResultException ex) {
}
request.getRequestDispatcher(VIEW).forward(request, response);
} |
9ef98fc7-d5bd-41bb-964a-bd4b1a2c564e | @Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
if (!request.getParameter("aantal").isEmpty()) {
try {
int aantal = Integer.parseInt(request.getParameter("aantal"));
if (aantal > 0) {
HttpSession session = request.getSession();
@SuppressWarnings("unchecked")
Map<Long, Integer> mandje = (Map<Long, Integer>) session
.getAttribute("mandje");
if (mandje == null) {
mandje = new HashMap<>();
}
mandje.put(Long.parseLong(request.getParameter("bierNr")),
aantal);
session.setAttribute("mandje", mandje);
response.sendRedirect(response.encodeRedirectURL(String
.format(REDIRECT_URL, request.getContextPath())));
} else {
request.setAttribute("fout",
"Getal moet groter dan 0 zijn.");
this.doGet(request, response);
}
} catch (NumberFormatException ex) {
request.setAttribute("fout", "Enkel getallen invullen");
this.doGet(request, response);
}
} else {
request.setAttribute("fout", "Getal mag niet leeg zijn");
this.doGet(request, response);
}
} |
4136f422-01dd-4455-80fb-1631611457b4 | @Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session != null) {
@SuppressWarnings("unchecked")
Map<Long, Integer> mandje = (Map<Long, Integer>) session
.getAttribute("mandje");
if(mandje!=null){
List<Long> bierenIdLijst = new ArrayList<>();
for (long bierId : mandje.keySet()) {
bierenIdLijst.add(bierId);
}
Set<BestelbonLijn> bestelbonLijnen = new HashSet<>();
List<Bier> bierenLijst = (List<Bier>) bierService
.findAllById(bierenIdLijst);
for (Bier bier : bierenLijst) {
bestelbonLijnen.add(new BestelbonLijn(mandje.get(bier
.getBierNr()), bier));
}
request.setAttribute("mandje",
new Bestelbon(bestelbonLijnen));
}
}
request.getRequestDispatcher(VIEW).forward(request, response);
} |
fd3868f2-cd95-4173-9452-a22f3f41d212 | @Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession(false);
if (session != null) {
@SuppressWarnings("unchecked")
Map<Long, Integer> mandje = (Map<Long, Integer>) session
.getAttribute("mandje");
if (mandje != null) {
Map<String, String> fouten = new HashMap<>();
String naam = validateString(request.getParameter("naam"));
if(naam.equals("Verplicht.")||naam.equals("Te lang. Max 50 tekens.")){
fouten.put("naam", naam);
}
String straat = validateString(request.getParameter("straat"));
if(straat.equals("Verplicht.")||straat.equals("Te lang. Max 50 tekens.")){
fouten.put("straat", straat);
}
String huisNr = validateString(request.getParameter("huisNr"));
if(huisNr.equals("Verplicht.")||huisNr.equals("Te lang. Max 50 tekens.")){
fouten.put("huisNr", huisNr);
}
int postCode = 0;
if(!request.getParameter("postCode").isEmpty()){
try{
postCode = Integer.parseInt(request.getParameter("postCode"));
if (postCode < 1000 || postCode > 9999) {
fouten.put("postCode", "Tik een positief getal tussen 1000 en 9999");
}
}catch(NumberFormatException ex){
fouten.put("postCode", "Tik een positief getal tussen 1000 en 9999");
}
} else {
fouten.put("postCode", "Verplicht.");
}
String gemeente = validateString(request.getParameter("gemeente"));
if(gemeente.equals("Verplicht.")||gemeente.equals("Te lang. Max 50 tekens.")){
fouten.put("gemeente", gemeente);
}
if(fouten.isEmpty()){
Adres adres = new Adres(straat, huisNr, postCode, gemeente);
Set<BestelbonLijn> bestelbonLijnen = new HashSet<>();
for (Entry<Long, Integer> entry : mandje.entrySet()) {
bestelbonLijnen.add(new BestelbonLijn(entry.getValue(),
bierService.read(entry.getKey())));
}
Bestelbon bestelbon = new Bestelbon(naam, adres, bestelbonLijnen);
bestelbonService.create(bestelbon);
session.invalidate();
request.setAttribute("bestelbon", bestelbon.getBonNr());
request.getRequestDispatcher(REDIRECT_URL).forward(request, response);}
else{
request.setAttribute("fouten", fouten);
this.doGet(request, response);
}
}
}
} |
4366b68b-d15d-43b6-857d-de234dc176be | public String validateString(String string){
if(string.isEmpty()){
return "Verplicht.";
}
else{
if(string.length()>50){
return "Te lang. Max 50 tekens.";
}
else{
return string;
}
}
} |
731aaf27-5be3-48d8-aead-787f01751d30 | @Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session != null) {
request.setAttribute("mandje", session.getAttribute("mandje"));
}
request.setAttribute("aantalBieren", bierService.countAll());
request.getRequestDispatcher(VIEW).forward(request, response);
} |
3471fc21-1f65-4fd7-ab3b-db7113bd0bb0 | protected Adres(){
} |
776e6d68-3c25-4ad4-8539-8a076610f069 | public Adres(String straat, String huisNr, int postCode, String gemeente){
this.straat=straat;
this.huisNr=huisNr;
this.postCode=postCode;
this.gemeente=gemeente;
} |
798cb955-5bd8-4ac2-9721-aef89b425084 | public String getGemeente() {
return gemeente;
} |
60e49040-fdb0-4d8f-97c9-a69d8cfe611e | protected BestelbonLijn(){
} |
2fffb0cc-428d-4e87-9397-fb5c126bb713 | public int getAantal() {
return aantal;
} |
9855d568-3ebe-48df-8b3f-62628513fc73 | public Bier getBier() {
return bier;
} |
f227f62b-0180-4bf7-b989-658c8fd1f5ae | public BestelbonLijn(int aantal, Bier bier){
this.aantal=aantal;
this.bier=bier;
} |
005ce3b1-e573-4483-822e-6dad5e72d5e0 | public BigDecimal getTotaal() {
return bier.getPrijs().multiply(BigDecimal.valueOf(aantal));
} |
7d527eab-ab70-40ee-a9b1-8a7b41bec2b5 | @Override
public boolean equals(Object object){
if(!(object instanceof BestelbonLijn)){
return false;
}
else{
BestelbonLijn andereBestelbonLijn = (BestelbonLijn) object;
return(bier.getNaam().equals(andereBestelbonLijn.getBier().getNaam()) &&
bier.getBrouwer().getNaam().equals(andereBestelbonLijn.getBier().getBrouwer().getNaam()));
}
} |
7c0df7e4-4dd2-4e2c-b49e-525b9b36b0ec | @Override
public int hashCode() {
String hashCode = bier.getNaam()+bier.getBrouwer().getNaam();
return hashCode.hashCode();
} |
d3d8c3cb-164e-4744-a635-75939182d92c | public Iterable<Brouwer> findAll(){
return brouwerDAO.findAll();
} |
5c0ce433-9443-4bd5-a422-8016ccc218fc | public Brouwer readBrouwerAndBier(long id){
return brouwerDAO.readBrouwerAndBier(id);
} |
421bf6e3-5563-499f-8879-e6b57e86d110 | public void create (Bestelbon bestelbon){
bestelbonDAO.beginTransaction();
bestelbonDAO.create(bestelbon);
bestelbonDAO.commit();
} |
fb681d3d-d4c4-4822-ab04-ce7dba51fa16 | public Bier read(long id){
return bierDAO.read(id);
} |
8f1d771e-66c6-457a-a30c-1bc15bed7333 | public long countAll(){
return bierDAO.countAll();
} |
dfef0148-c357-4595-8e5a-d946fe102a04 | public Bier readBierSoortAndBrouwer(long id){
return bierDAO.readBierSoortAndBrouwer(id);
} |
c15540bf-6ec8-46a3-b8a8-3fa3159c5e1e | public Iterable<Bier> findAllById(List<Long> id) {
return bierDAO.findAllById(id);
} |
bd4c4481-04a3-4e7c-a91f-6e1319ad230e | @Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext context = filterConfig.getServletContext();
context.setAttribute("contextPath", context.getContextPath());
} |
a2120766-8dc3-4b28-a438-96dcff75135d | @Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException {
entityManagers.set(entityManagerFactory.createEntityManager());
try {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
} finally {
EntityManager entityManager = entityManagers.get();
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
}
entityManager.close();
entityManagers.remove();
}
} |
5f734cea-c0d1-4505-9e2f-a54ea52d6281 | @Override
public void destroy() {
entityManagerFactory.close();
} |
b8088d59-db90-4bda-9025-03c8b659eaaf | public static EntityManager getEntityManager() {
return entityManagers.get();
} |
612d4db1-678c-4f18-9620-ca9b8b6e2a06 | public void create(Bestelbon bestelbon ) {
getEntityManager().persist(bestelbon);
} |
b5c79644-aa3a-408b-8fca-8ad95b80c4a5 | public Bier read(long id) {
return getEntityManager().find(Bier.class, id);
} |
93f34197-493d-439b-b49e-7fa49dc7c120 | public long countAll() {
return getEntityManager()
.createNamedQuery("Bier.countAll", Long.class)
.getSingleResult();
} |
37e3c3c9-f676-4ca9-bafa-5a1804357a15 | public Bier readBierSoortAndBrouwer(long id){
return getEntityManager()
.createNamedQuery("Bier.readBierSoortAndBrouwer", Bier.class)
.setParameter("id", id)
.getSingleResult();
} |
1f87da4e-1db4-48cf-97a0-358ba56a3218 | public Iterable<Bier> findAllById(List<Long> id) {
return getEntityManager()
.createNamedQuery("Bier.findAllById", Bier.class)
.setParameter("id", id).getResultList();
} |
52aac7cf-d7e8-4091-bd37-f03d1b00cc1e | protected EntityManager getEntityManager() {
return JPAFilter.getEntityManager();
} |
27bd69a7-b86c-4650-a64a-0315639e619e | public void beginTransaction() {
getEntityManager().getTransaction().begin();
} |
b2853498-4cd8-49ff-b240-fd48bc5baf9b | public void commit() {
getEntityManager().getTransaction().commit();
} |
3b4ec9fc-dbff-49fa-a00f-0369f6bb16c8 | public void rollback() {
getEntityManager().getTransaction().rollback();
} |
b6c950ce-8719-4957-b806-6e52d3bb40f9 | public Iterable<Brouwer> findAll() {
return getEntityManager()
.createNamedQuery("Brouwer.findAll", Brouwer.class)
.getResultList();
} |
8013635e-6889-44bb-bd24-fb0e6877ff21 | public Brouwer readBrouwerAndBier(long id){
return getEntityManager()
.createNamedQuery("Brouwer.readBrouwerAndBier", Brouwer.class)
.setParameter("id", id)
.getSingleResult();
} |
d417630e-04f9-49ce-a3ca-338e97bec3f7 | TxThread(String ip)
{
ipaddr=ip;
start();
} |
1ba7559a-9a56-4dfc-bd41-21900e65030e | public void run()
{
Transmitter t=new Transmitter();
try {
t.captureAudio(ipaddr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
15ed0c95-800b-4427-99da-38ec6f45ffb3 | RxThread()
{
start();
} |
a59123dc-339f-48ce-b5b8-99ce31c3930d | public void run()
{
try
{
try {
Receiver r=new Receiver();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (LineUnavailableException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
c05c4a23-7b88-4da3-a799-9e29935da5f4 | public AudioGUI() {
initComponents();
} |
e54bc579-8d1b-4624-8024-9d90b86b55a7 | private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
IPAddress = new javax.swing.JTextField();
LoginButton = new javax.swing.JButton();
LogOut = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
jLabel1.setText("Audio Chat Client");
jLabel2.setText("IP Address");
LoginButton.setText("Log In");
LoginButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LoginButtonActionPerformed(evt);
}
});
LogOut.setText("Log Out");
LogOut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LogOutActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(123, 123, 123)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(LoginButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(LogOut))
.addComponent(IPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(40, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(IPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(LoginButton)
.addComponent(LogOut))
.addContainerGap(33, Short.MAX_VALUE))
);
pack();
}// </editor-fold> |
c67184e1-f25e-4bb2-84fd-58391300e665 | public void actionPerformed(java.awt.event.ActionEvent evt) {
LoginButtonActionPerformed(evt);
} |
b1f786cc-475e-4e6e-aaab-67bc4f60994a | public void actionPerformed(java.awt.event.ActionEvent evt) {
LogOutActionPerformed(evt);
} |
a123af57-9d0a-451a-955d-c9491edca816 | private void LogOutActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
t1.stop();
t2.stop();
IPAddress.setEditable(true);
} |
3c6f677f-7f84-4e50-b41b-abb6cb474acb | private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
String ipaddress=IPAddress.getText();
System.out.println(ipaddress);
IPAddress.setEditable(false);
t1=new TxThread(ipaddress);
t2=new RxThread();
t1.run();
t2.run();
} |
40bb68bc-340c-4da3-903a-108646d9d783 | public void audioChat() {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AudioGUI().setVisible(true);
}
});
} |
241d3857-6aa3-4ba7-9874-9390b7139081 | public void run() {
new AudioGUI().setVisible(true);
} |
7eb46c5e-c9df-4ef5-961f-c6933df679fc | Receiver() throws LineUnavailableException, IOException{
try {
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info( SourceDataLine.class,audioFormat);
sourceDataLine = (SourceDataLine)
AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
MyService = new ServerSocket(502);
clientSocket = MyService.accept();
captureAudio();
input = new BufferedInputStream(clientSocket.getInputStream());
out=new BufferedOutputStream(clientSocket.getOutputStream());
while(input.read(tempBuffer)!=-1){
sourceDataLine.write(tempBuffer,0,500);
}
} catch (IOException e) {
e.printStackTrace();
sourceDataLine.close();
MyService.close();
clientSocket.close();
}
} |
3959e38c-2d48-4494-9911-fcadfb326895 | private AudioFormat getAudioFormat(){
float sampleRate = 8000.0F;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(
sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
} |
6ea560f2-df0e-4ba2-95be-797f840249fc | private void captureAudio() {
try {
/*Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
System.out.println("Available mixers:");
for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
System.out.println(mixerInfo[cnt].getName());
}*/
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
TargetDataLine.class, audioFormat);
/*Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);
targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);*/
targetDataLine = (TargetDataLine)
AudioSystem.getLine(
dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
Thread captureThread = new CaptureThread();
captureThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
} |
226913e2-f9e4-4387-bb46-6baf9fedbddc | public void run() {
try {
while (true) {
int cnt = targetDataLine.read(tempBuffer, 0,
tempBuffer.length);
out.write(tempBuffer);
}
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
} |
b3dfccbf-d4c6-4031-ae62-435b864b24d3 | void captureAudio(String ipaddr) throws IOException {
try {
System.out.println("IPAddress "+ipaddr+" "+502);
sock = new Socket(ipaddr, 502);
out = new BufferedOutputStream(sock.getOutputStream());
in = new BufferedInputStream(sock.getInputStream());
/*Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
System.out.println("Available mixers:");
for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
System.out.println(mixerInfo[cnt].getName());
}*/
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
TargetDataLine.class, audioFormat);
/*Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);
targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
*/
targetDataLine = (TargetDataLine)
AudioSystem.getLine(
dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
Thread captureThread = new CaptureThread();
captureThread.start();
DataLine.Info dataLineInfo1 = new DataLine.Info(
SourceDataLine.class, audioFormat);
sourceDataLine = (SourceDataLine) AudioSystem
.getLine(dataLineInfo1);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
Thread playThread = new PlayThread();
playThread.start();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
sock.close();
sourceDataLine.close();
System.exit(0);
}
} |
4c890bfe-07df-4fbe-97f0-ee52392b1907 | public void close()
{
try {
sock.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
732c2708-6051-40d8-8186-6dee1dba06dc | public void run() {
byteArrayOutputStream = new ByteArrayOutputStream();
stopCapture = false;
try {
while (!stopCapture) {
int cnt = targetDataLine.read(tempBuffer, 0,
tempBuffer.length);
out.write(tempBuffer);
if (cnt > 0) {
byteArrayOutputStream.write(tempBuffer, 0, cnt);
}
}
byteArrayOutputStream.close();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
System.exit(0);
}
} |
f06ffecc-1d99-4c14-801e-0741015da025 | private AudioFormat getAudioFormat() {
float sampleRate = 8000.0F;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
bigEndian);
} |
7e340b29-9826-4675-b29b-c6887cda5ada | public void run() {
try {
while (in.read(tempBuffer) != -1) {
sourceDataLine.write(tempBuffer, 0, 500);
}
} catch (IOException e) {
e.printStackTrace();
}
} |
e56bed48-41c0-41fa-b5dc-8f1a8d95c07d | public ClientGUI() {
initComponents();
} |
be0ff9d7-6334-45a4-af43-3439c561d940 | public void run() {
String stream;
String[] data;
String done = "Done", connect = "Connect", disconnect = "Disconnect", chat = "Chat";
try {
while ((stream = stdin.readLine()) != null) {
data = stream.split("\21");
if (data[2].equals(chat)) {
outputText.append(data[0] + ": " + data[1] + "\n");
} else if (data[2].equals(connect)){
outputText.removeAll();
userList.add(data[0]);
} else if (data[2].equals(disconnect)) {
outputText.append(data[0] + " has logged out.\n");
} else if (data[2].equals(done)) {
chatRoomUsers.setText("");
//writeUsers();
for(int i=0;i<userList.size();i++)
{
chatRoomUsers.append(userList.get(i)+"\n");
}
userList.clear();
}
}
}catch(Exception ex) {
}
} |
27fcf280-65d2-459f-a9de-5ea9df7fd57f | public void ListenThread()
{
Thread DataAnalyser = new Thread(new DataAnalyser());
DataAnalyser.start();
} |
df9c655f-cf82-4185-aad8-dd122554e8fb | public void Disconnect()
{
try {
outputText.append("Disconnected....You have been successfully Logged out!\n");
socket.close();
} catch(Exception ex) {
outputText.append("Oops! Log out failed \n");
}
isConnected = false;
usernameField.setEditable(true);
ipAddress.setEditable(true);
chatRoomUsers.setText("");
} |
8738ceb6-0167-450b-be83-3289d3dc89ff | public void performLogOut() {
String bye = (userid + "\21 \21Disconnect");
try{
stdout.println(bye); // Sends server the signal to log out.
stdout.flush(); // flushes the buffer
} catch (Exception e) {
outputText.append("Error occured while sending log out message\n");
}
} |
a7fa2e76-1b51-4e75-ab77-ce9efcd2d02c | private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
inputText = new javax.swing.JTextArea();
sendButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
chatRoomUsers = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
outputText = new javax.swing.JTextArea();
usernameField = new javax.swing.JTextField();
loginButton = new javax.swing.JButton();
logoutButton = new javax.swing.JButton();
audioChatButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
ipAddress = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
inputText.setColumns(20);
inputText.setRows(5);
jScrollPane1.setViewportView(inputText);
sendButton.setText("Send");
sendButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendButtonActionPerformed(evt);
}
});
chatRoomUsers.setEditable(false);
jScrollPane2.setViewportView(chatRoomUsers);
outputText.setColumns(20);
outputText.setEditable(false);
outputText.setRows(5);
jScrollPane3.setViewportView(outputText);
usernameField.setText("username");
loginButton.setText("Login");
loginButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginButtonActionPerformed(evt);
}
});
logoutButton.setText("Logout");
logoutButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
logoutButtonActionPerformed(evt);
}
});
audioChatButton.setText("Voice");
audioChatButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
audioChatButtonActionPerformed(evt);
}
});
jLabel1.setText("Chat Room");
ipAddress.setText("IP Address");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(ipAddress, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(logoutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(audioChatButton, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sendButton)))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(sendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(usernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(loginButton)
.addComponent(logoutButton)
.addComponent(audioChatButton)
.addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
pack();
}// </editor-fold> |
61e55739-ccdc-46ae-9e9c-1efbcb1c5fc6 | public void actionPerformed(java.awt.event.ActionEvent evt) {
sendButtonActionPerformed(evt);
} |
3127325c-c96f-4fa2-84d1-60ca94f801a7 | public void actionPerformed(java.awt.event.ActionEvent evt) {
loginButtonActionPerformed(evt);
} |
68f9b289-07b8-4bae-9622-86f0a55ae4bf | public void actionPerformed(java.awt.event.ActionEvent evt) {
logoutButtonActionPerformed(evt);
} |
879e6cf9-c310-4a83-a7ec-67767ab4fe10 | public void actionPerformed(java.awt.event.ActionEvent evt) {
audioChatButtonActionPerformed(evt);
} |
dc07bc87-2e62-4b07-b777-ae5e4345d2ce | private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt)
{
performLogOut();
Disconnect();
} |
a97d4cd9-5790-486c-a8bf-bf6a1607170a | private void audioChatButtonActionPerformed(java.awt.event.ActionEvent evt)
{
AudioGUI aud=new AudioGUI();
aud.audioChat();
} |
c5d8ef59-2378-45f9-8af7-de19124f431e | private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed
// TODO add your handling code here:
if (isConnected == false) {
userid = usernameField.getText();
usernameField.setEditable(false);
ipAddress.setEditable(false);
try {
socket = new Socket(ipAddress.getText(), 7000);
InputStreamReader streamreader = new InputStreamReader(socket.getInputStream());
stdin = new BufferedReader(streamreader);
stdout = new PrintWriter(socket.getOutputStream());
stdout.println(userid + "\21has logged in.\21Connect"); // Displays to everyone that user connected.
stdout.flush(); // flushes the buffer
isConnected = true; // Used to see if the client is connected.
} catch (Exception ex) {
outputText.append("Failed to connect to Server! Try Again. \n");
usernameField.setEditable(true);
ipAddress.setEditable(true);
}
ListenThread();
} else if (isConnected == true) {
outputText.append("You are already part of the chat. \n");
}
} |
1d116139-d98a-4998-8be9-fa5bc436260d | private void sendButtonActionPerformed(java.awt.event.ActionEvent evt)
{
if((inputText.getText()).equals(""))
{
inputText.setText("");
inputText.requestFocus();
}
else {
try {
stdout.println(userid + "\21" + inputText.getText() + "\21" + "Chat");
stdout.flush(); // flushes the buffer
} catch (Exception ex) {
chatRoomUsers.append("Message was not sent. \n");
}
inputText.setText("");
inputText.requestFocus();
}
inputText.setText("");
inputText.requestFocus();
} |
0b6098bb-6f58-4bae-84b2-37e040f680a2 | public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClientGUI().setVisible(true);
}
});
} |
0a2ff57e-33c5-493f-80ac-9ae2015d1166 | public void run() {
new ClientGUI().setVisible(true);
} |
bb6e1d8a-888f-4731-8f05-6850d8ce7476 | public ClientThread(Socket clientSocket, PrintWriter user)
{
client = user;
try
{
socket = clientSocket;
InputStreamReader isReader = new InputStreamReader(socket.getInputStream());
reader = new BufferedReader(isReader);
}
catch (Exception ex)
{
System.out.println("Stream Reader failed to intialise");
}
} |
bca607d8-7655-453d-86fb-f28839bd217e | public void run()
{
String message;
String[] data;
String connect = "Connect";
String disconnect = "Disconnect";
String chat = "Chat";
try
{
while ((message = reader.readLine()) != null)
{
System.out.println("Received: " + message);
data = message.split("\21");
for (String token:data)
{
System.out.println(token);
}
if (data[2].equals(connect))
{
broadcastFrame((data[0] + "\21" + data[1] + "\21" + chat));
userAdd(data[0]);
}
else if (data[2].equals(disconnect))
{
broadcastFrame((data[0] + "\21has logged off." + "\21" + chat));
userRemove(data[0]);
}
else if (data[2].equals(chat))
{
broadcastFrame(message);
}
else
{
System.out.println("Invalid Frame!");
}
}
}
catch (Exception ex)
{
System.out.println("Connect was lost");
clientStreams.remove(client);
}
} |
ffa78d44-98a0-47ae-a6fb-ea6c65a0a6f2 | public static void main (String[] args)
{
new Server().go();
} |
09f1db7d-853c-4086-8236-67737ece31e0 | public void go()
{
clientStreams = new ArrayList();
try {
ServerSocket serverSock = new ServerSocket(7000);
while (true) {
/* set up the server writer function and then begin at the same
the listener using the Runnable and Thread */
Socket clientSock = serverSock.accept();
PrintWriter writer = new PrintWriter(clientSock.getOutputStream());
clientStreams.add(writer);
// use a Runnable to start a 'second main method that will run
// the listener
Thread listener = new Thread(new ClientThread(clientSock, writer));
listener.start();
System.out.println("got a connection");
} // end while
} // end try
catch (Exception ex)
{
System.out.println("error making a connection");
ex.printStackTrace();
} // end catch
} // end go() |
2837cf04-b19a-4751-a780-f150dca0c19a | public void userAdd (String data) {
String message;
String add = "\21 \21Connect", done = "Server\21 \21Done";
userList.add(data);
String[] tempList = new String[(userList.size())];
userList.toArray(tempList);
for (String token:tempList) {
message = (token + add);
broadcastFrame(message);
}
broadcastFrame(done);
} |
c4836ff3-4d1a-4936-8b46-88debd5eaa4e | public void userRemove (String data)
{
String message;
String add = "\21 \21Connect", done = "Server\21 \21Done";
userList.remove(data);
String[] tempList = new String[(userList.size())];
userList.toArray(tempList);
for (String token:tempList) {
message = (token + add);
broadcastFrame(message);
}
broadcastFrame(done);
} |
370c2d77-6e36-407f-9852-c3ee52fe69e4 | public void broadcastFrame(String message) {
// sends message to all the clients connected to server
Iterator it = clientStreams.iterator();
while (it.hasNext()) {
try {
PrintWriter writer = (PrintWriter) it.next();
writer.println(message);
System.out.println("Sending" + message);
writer.flush();
}
catch (Exception ex) {
System.out.println("error telling everyone");
}
}
} |
0a685e3a-9707-42df-b3e9-a386978ce4ef | public PlayerShip(int _x, int _y) {
x = _x + U.world_x_pixels2;
y = _y + U.world_y_pixels2;
ship = new ShipGraphic(1);
r = 4;
Reset();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.